0 Replies Latest reply on Jun 8, 2015 4:03 PM by 2967007

    JPA optimistic issue with EJB REQUIRES_NEW method


      We used EJB 3.2 and JPA 2.1 with eclipselink 2.5.2 and Glassfish 4.1.All entities have version field.

      Our scenario is a workflow that call variant nodes and recognize next node is dynamic. All nodes call in one transaction that create in begin of workflow method. When node with specific state (etc manual) reached, transaction committed and workflow wait for signal from user and continues flow to reach finish node. We call legacy service in some nodes that have not a XA transaction availability. For keep workflow state used Journal entity that retain node call data. Journal entity update in any workflow node.

      My problem is that because xe transaction is not available if legacy service calls and after call exception throws and transaction rollback, legacy response lost and try again to start the workflow of begin cause generated incorrect data. So, I’m forced use REQUIRES_NEW method that commit journal entity before and after call legacy service. Because persistence context of two transaction different, Optimistic lock thrown and entity changed in T1 not persiste in another context. If passed entitymanager with SynchronizationType.SYNCHRONIZED type to another transaction, changes apply if entitymanager flush mode is FlushModeType.COMMIT. In these situations, if in any node before commit journal entity in T2 transaction, used Query API on the journal entity, according JPA spec changes on this entity is not considered :

      “3.10.8 : If FlushModeType.COMMIT is set, the effect of updates made to entities in the persistence context upon queries is unspecified.”

      What is best practice for call new transaction and apply change on the entity that it used in suspend transaction with version field?