Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-17169

[GSS](7.2.z) HHH-13492 - OptimisticLockException after lock, refresh, merge in a transaction

XMLWordPrintable

    • +
    • Hide
      1. Employee e = entityManager.find(Employee.class, THE_KEY_HERE);
      2. entityManager.lock(e, LockModeType.READ);
      3. entityManager.refresh(e);
      4. Update some property of the entity (and merge)
      5. Commit
      Show
      Employee e = entityManager.find(Employee.class, THE_KEY_HERE); entityManager.lock(e, LockModeType.READ); entityManager.refresh(e); Update some property of the entity (and merge) Commit

      Update of an entity with a Version property in a transaction, after lock and refresh, results in an OptimisticLockException during commit.

      ... javax.persistence.OptimisticLockException: Newer version [2] of entity [[support.hibernate.entity.Employee#THE_KEY_HERE]] found in database
      	at org.hibernate.internal.ExceptionConverterImpl.wrapLockException(ExceptionConverterImpl.java:247)
      	at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:103)
      	at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
      	at org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:60)
      	... 29 more
      Caused by: org.hibernate.OptimisticLockException: Newer version [2] of entity [[support.hibernate.entity.Employee#THE_KEY_HERE]] found in database
      	at org.hibernate.action.internal.EntityVerifyVersionProcess.doBeforeTransactionCompletion(EntityVerifyVersionProcess.java:51)
      	at org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:954)
      	at org.hibernate.engine.spi.ActionQueue.beforeTransactionCompletion(ActionQueue.java:525)
      	at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2487)
      	at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:473)
      	at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:178)
      	at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:39)
      	at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:271)
      	at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:104)
      	...
      

              gbadner@redhat.com Gail Badner (Inactive)
              rhn-support-sfikes Stephen Fikes (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: