Francisco Osorio [
https://community.jboss.org/people/fosoriog] created the discussion
"How to avoid StaleObjectExceptions on asynchronous process"
To view the discussion, visit:
https://community.jboss.org/message/756581#756581
--------------------------------------------------------------
I have a process that uses an asyncrhonous work item handler to execute several branches
in parallel. I'm using JPAWorkingMemoryDbLogger to persist the log to the database.The
issue is that the commit for the completeWorkItem invocation fails with
StaleObjectException on those threads.
It seems the completeWorkItem invocations are attempting to update the
org.drools.persistence.info.SessionInfo entity, and it fails because a optimistick lock
exception. (That entity was modified first when the session.startProcessInstance commited
to the database).
Here is the exception:
2012-08-28 15:13:20,962 [Thread-6] DEBUG (SQLStatementLogger.java:111) - update
SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where
id=? and OPTLOCK=?
org.hibernate.StaleStateException: Unexpected row count: 0; expected: 1
at
org.hibernate.jdbc.Expectations$BasicExpectation.checkNonBatched(Expectations.java:102)
at
org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:67)
at
org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1774)
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2425)
at
org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2325)
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2625)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
at
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512)
at
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at
com.mypackage.workflow.impl.jbpm.runtime.workitemhandlers.WebServiceWorkItemHandler$1.run(WebServiceWorkItemHandler.java:178)
at java.lang.Thread.run(Thread.java:662)
2012-08-28 16:16:21,779 [Thread-4] ERROR (AbstractFlushingEventListener.java:324) - Could
not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction
(or unsaved-value mapping was incorrect): [org.drools.persistence.info.SessionInfo#281]
at
org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1782)
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2425)
at
org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2325)
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2625)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
at
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512)
at
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at
com.mypackage.workflow.impl.jbpm.runtime.workitemhandlers.WebServiceWorkItemHandler$1.run(WebServiceWorkItemHandler.java:178)
at java.lang.Thread.run(Thread.java:662)
I've seen this kind of issue reported in other discussions in the forum, but at the
moment I don't think an answer has been given. It seems to be an issue in the jbpm
persistence engine, but I might be mistaken and I might be doing something wrong.
So, how could I avoid these exceptions?
Thanks
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/756581#756581]
Start a new discussion in jBPM at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]