anonymous wrote : | The approach I was trying to use: | | AEntity a = manager.find(AEntity.class, aId); | manager.lock(a, LockModeType.READ); | | I think now it's not the way to go, because it's not atomic: Different competing threads could adquire an entity representing that database row before one of then reaches the lock. |
I had a simlar problem and came up with this solution: Since multiple threads can get then entity before locking it, once you get the lock, refresh the entitiy, then you will have the latest copy and you can then update it without overwriting previous updates: | AEntity a = manager.find(AEntity.class, aId); | manager.lock(a, LockModeType.READ); | manager.refresh(a); | // now do stuff | View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3980871#3980871 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3980871 _______________________________________________ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user