2 Replies Latest reply on Oct 8, 2011 2:03 PM by trollfar

    Entity with @OptimisticLocking(type=OptimisticLockType.ALL) and find with actually LockModeType=OPTIMISTIC

    trollfar

      Does anybody know if @OptimisticLocking(type=OptimisticLockType.ALL) works at all?

       

      Tried in AS7.0.1 and in AS6.1.0 with bundled Hibernate versions ( 4.0.0.Beta4 resp 3.6.6), but as soon as entities are looked up by find(class,key,LockModeType.OPTIMISTIC) Hibernate will crash on null pointer exception during commit. Stack trace is (in AS 6.1.0)

       

      22:49:18,924 ERROR [org.hibernate.AssertionFailure] an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): java.lang.NullPointerException

          at org.hibernate.action.EntityVerifyVersionProcess.doBeforeTransactionCompletion(EntityVerifyVersionProcess.java:56) [:3.6.6.Final]

          at org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:543) [:3.6.6.Final]

          at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:216) [:3.6.6.Final]

          at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:571) [:3.6.6.Final]

          at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:250) [:3.6.6.Final]

          at org.hibernate.transaction.synchronization.CallbackCoordinator.beforeCompletion(CallbackCoordinator.java:125) [:3.6.6.Final]

          at org.hibernate.transaction.synchronization.HibernateSynchronizationImpl.beforeCompletion(HibernateSynchronizationImpl.java:51) [:3.6.6.Final]

          at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:97) [:6.1.0.Final]

          at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:274) [:6.1.0.Final]

          at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:94) [:6.1.0.Final]

          at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:159) [:6.1.0.Final]

          at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1158) [:6.1.0.Final]

          at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:119) [:6.1.0.Final]

          at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75) [:6.1.0.Final]

          at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:162) [:6.1.0.Final]

       

      Should mention that transaction is bean-managed and dbms is MySQL 5.1. When not setting LockModeType.OPTIMISTIC it sort of works, but then there is no concurrency check and inconsistent transactions are let through, overwriting each other.

       

      Anybody found any way at all to use optimistic concurrency control without @version columns in DB? Thanks for your help

        • 1. Re: Entity with @OptimisticLocking(type=OptimisticLockType.ALL) and find with actually LockModeType=OPTIMISTIC
          smarlow

          I'm not sure if its a known issue or not.  Have you tried searching the Hibernate bug system https://hibernate.onjira.com/browse/HHH?  A google (or your favorite search engine) search might also be something to try. 

           

          From looking at the code at line 56 in EntityVerifyVersionProcess.java, it looks like the Hibernate object representation for version, is null.  You mentioned @Version columns above.  I assume if you had a @Version column, you would bother using the ALL support.  Can you verify that you don't have a @version column mapped when this NullPointerException occurs?

           

          Create a new HHH jira at the above link if you cannot find an existing one.  Grabbing the Hibernate source from https://github.com/hibernate/hibernate-core and adding a unit test that recreates the issue to attach to the jira, would also be helpful.

          • 2. Re: Entity with @OptimisticLocking(type=OptimisticLockType.ALL) and find with actually LockModeType=OPTIMISTIC
            trollfar

            Thanks, true, I do not have a version column.  Couldn't find the issue in onjira, but it turns out that it has been "corrected" in 4.0.0.CR2 (AS 7.0.2) by throwing a not-yet-implemented-exception.

             

            Also found that if I do have a @Version attribute in the class, the @OptimisticLocking(type=OptimisticLockType.ALL) seems to give EXACTLY the same behaviour as when having @OptimisticLocking(type=OptimisticLockType.VERSION).

             

            So in all, I do not see why there is a type=OptimisticLockType.ALL; its a Hibernate extension to JPA which is not implemented... In summary you cannot use optimistic locking unless you may add a version column to your database.

            1 of 1 people found this helpful