Pages

Tuesday, June 6, 2017

How to solve Optimistic locking error if you get with WSO2 BPS with Oracle combination

There is possibility to get transaction warning optimistic locking error as shown below

[BPELServer-3] [2016-03-29 06:45:41,125]  WARN {Transaction} -  Unexpected exception from beforeCompletion; transaction will roll back
org.apache.openjpa.persistence.OptimisticLockException: Optimistic locking errors were detected when flushing to the data store.  The following objects may have been concurrently modified in another transaction: [org.apache.ode.dao.jpa.MessageDAOImpl@21dae500, org.apache.ode.dao.jpa.MessageDAOImpl@45fcaea2, org.apache.ode.dao.jpa.MessageDAOImpl@497908f1, org.apache.ode.dao.jpa.MessageDAOImpl@47bbc1bc, org.apache.ode.dao.jpa.MessageDAOImpl@6334d00f, org.apache.ode.dao.jpa.MessageDAOImpl@39c2059, org.apache.ode.dao.jpa.MessageDAOImpl@773f167b, org.apache.ode.dao.jpa.MessageDAOImpl@6eeda72e]
at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2326)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2174)
at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2072)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1843)
at org.apache.openjpa.kernel.DelegatingBroker.flush(DelegatingBroker.java:1045)
at org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:663)
at org.apache.ode.dao.jpa.ProcessInstanceDAOImpl.delete(ProcessInstanceDAOImpl.java:227)
at org.apache.ode.bpel.engine.BpelRuntimeContextImpl$2.beforeCompletion(BpelRuntimeContextImpl.java:254)
at org.apache.ode.scheduler.simple.SimpleScheduler$2.beforeCompletion(SimpleScheduler.java:340)
at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:514)
at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:498)
at org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:400)
at org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:257)
at org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:238)
at org.apache.ode.scheduler.simple.SimpleScheduler.execTransaction(SimpleScheduler.java:298)
at org.apache.ode.scheduler.simple.SimpleScheduler.execTransaction(SimpleScheduler.java:246)
at org.apache.ode.scheduler.simple.SimpleScheduler$RunJob.call(SimpleScheduler.java:541)
at org.apache.ode.scheduler.simple.SimpleScheduler$RunJob.call(SimpleScheduler.java:525)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.openjpa.persistence.OptimisticLockException: An optimistic lock violation was detected when flushing object instance "org.apache.ode.dao.jpa.MessageDAOImpl@21dae500" to the data store.  This indicates that the object was concurrently modified in another transaction.
FailedObject: org.apache.ode.dao.jpa.MessageDAOImpl@21dae500
at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.checkUpdateCount(BatchingPreparedStatementManagerImpl.java:303)
at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushBatch(BatchingPreparedStatementManagerImpl.java:186)
at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.batchOrExecuteRow(BatchingPreparedStatementManagerImpl.java:104)
at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:83)
at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:99)
at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:87)
at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:550)
at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:106)
at org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:103)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:713)
at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
... 21 more
....................

[BPELServer-3] [2016-03-29 06:45:41,148] DEBUG {org.apache.ode.bpel.engine.InstanceLockManager} -  Thread[BPELServer-3,5,main]: unlock(iid=253)
[BPELServer-3] [2016-03-29 06:45:41,149] DEBUG {org.apache.ode.bpel.engine.MyRoleMessageExchangeImpl} -  Received myrole mex response callback
[BPELServer-3] [2016-03-29 06:45:41,149]  WARN {org.apache.ode.bpel.engine.MyRoleMessageExchangeImpl} -  Transaction is rolled back on sending back the response.


This occurs with OpenJPA + Oracle combination (This occurred to me with Oracle 11g). According to [1] OpenJPA performs some statements as batches which may fail in several cases.

[1] https://wso2.org/jira/browse/CARBON-7500