1 Reply Latest reply on Aug 1, 2006 4:40 AM by Bhalchandra Gokhale

    help with optimistic locking

    Bhalchandra Gokhale Newbie

      I have an entity bean on these lines..

      User {
      @Version int version;

      @Id String id;


      Then I have a SLSB with this method:

      updateUser (User u) {
      EntityManager em;

      List dbUsers = em.createQuery("select from User u where u.name = 'user1').getResultList();
      User dbUser = dbUsers.get(0);



      i would have expected the version count of the user to be incremented. this does not happen.

      Then i tried with the following
      em.lock(dbUser, LockModeType.READ);
      and also em.lock(dbUser,LockModeType.WRITE);
      before the setter method.

      still the version does not get updated.

      What am i doing wrong here..

        • 1. Re: help with optimistic locking
          Bhalchandra Gokhale Newbie

          Furhter debugging resulted in this observation:

          in other than lockmode=write, the transaction gets committed.

          in the lockmode=write, this is what is happening:

          2006-08-01 13:34:58,765 ERROR [STDERR] at org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1282)
          2006-08-01 13:34:58,765 ERROR [STDERR] at org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:88)
          2006-08-01 13:34:58,765 ERROR [STDERR] at org.hibernate.event.def.DefaultLockEventListener.onLock(DefaultLockEventListener.java:64)
          2006-08-01 13:34:58,765 ERROR [STDERR] at org.hibernate.impl.SessionImpl.fireLock(SessionImpl.java:586)
          2006-08-01 13:34:58,765 ERROR [STDERR] at org.hibernate.impl.SessionImpl.lock(SessionImpl.java:578)
          2006-08-01 13:34:58,765 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.lock(AbstractEntityManagerImpl.java:337)
          2006-08-01 13:34:58,765 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManager.lock(TransactionScopedEntityManager.java:101)

          any known workarounds ? fixes ? patches or is it a wrong usage ?

          Thank You