[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - help with optimistic locking

balamg do-not-reply at jboss.com
Tue Aug 1 03:22:26 EDT 2006


I have an entity bean on these lines..

@Entity
User {
  @Version int version;
  
   @Id String id;

...
...
}

Then I have a SLSB with this method:

updateUser (User u) {
    @PersistenceContext
    EntityManager em;


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

    dbUser.setName("user2");
    
   
}

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..


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3962070#3962070

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3962070



More information about the jboss-user mailing list