Arjuna error when updating BDM object

Hi, 

in Bonita v7.12.7, i get  this stack trace when two task of my process are run in parallel (confirm email & confirm phone for example) Both tasks are updating a BDM field value, even if my process waits for task one completion

16-Sep-2021 17:25:39.802 WARN [Bonita-Worker-1-09] com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffff7f000001:faf5:61431b25:1ec9b, org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization@455a5e6b >
    javax.persistence.OptimisticLockException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.company.model.Customer#2]
        at org.hibernate.internal.ExceptionConverterImpl.wrapStaleStateException(ExceptionConverterImpl.java:223)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:93)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:188)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1348)
        at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:435)
        at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3221)
        at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2389)
        at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:447)
        at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.beforeCompletion(JtaTransactionCoordinatorImpl.java:355)
        at org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:47)
        at org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:37)
        at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76)
        at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:360)
        at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:91)
        at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
        at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1295)
        at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126)
        at org.bonitasoft.engine.transaction.JTATransactionServiceImpl.complete(JTATransactionServiceImpl.java:177)
        at org.bonitasoft.engine.transaction.JTATransactionServiceImpl.executeInTransaction(JTATransactionServiceImpl.java:279)
        at org.bonitasoft.engine.execution.work.TxBonitaWork.work(TxBonitaWork.java:41)
        at org.bonitasoft.engine.execution.work.LockProcessInstanceWork.work(LockProcessInstanceWork.java:68)
        at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:40)
        at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:40)
        at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:40)
        at org.bonitasoft.engine.execution.work.InSessionBonitaWork.work(InSessionBonitaWork.java:60)
        at org.bonitasoft.engine.work.BonitaThreadPoolExecutor.lambda$submit$1(BonitaThreadPoolExecutor.java:131)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
    Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.company.model.Customer#2]
        at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:2574)
        at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3420)
        at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3283)
        at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3695)
        at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:149)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
        at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478)
        at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
        at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:348)
        at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40)
        at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:108)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1344)
        ... 25 more
 

what's wrong in my process design ti get such error ?

Hi Laurent,

 

When you say parallel, you mean multinstatiated task in parallel? in this case, do you get your bdm object from a collection and save it in an iterator (fail).
or are several tasks in parallel thanks to a gateway? do you do anything with the bdm at the enter of the task that does that you keep a copy of the object?

hi Pablo,

this happens when I use parallel gateway with several tasks that update the same BDM field of my BDM object (customer.status) in operations based on tasks executor inputs 

my process looks like : start a case, trigger 2 human tasks: email & phone validation in //, both are updating a BDM field ("status") that contains a json text value containing all tasks results (passed/failed)