You are using a single session and a single transaction too. The database locks are re-entrant, as otherwise you would end up deadlocking by yourself. Change your example to start two sessions, each one with its own transaction. Then you'll see the second transaction waiting for the first one to...
hibernate,optimistic-locking,pessimistic-locking
I've found the reason why it's wasn't working. It's actually bug in hibernate 3.5-3.6 And it's fixed only in 4.0.1. https://hibernate.atlassian.net/browse/HHH-5275 So, I've ended with this workaround: MyObject myObject = criteria.uniqueResult(); MyObject lockedOne = (MyObject) session() .get(MyObject.class, myObject.getId(), LockMode.UPGRADE_NOWAT); ...
java,oracle,hibernate,jpa,pessimistic-locking
Finally i managed to make it work but with some modiffications. The idea is to use LockModeType.PESSIMISTIC_FORCE_INCREMENT instead of PESSIMISTIC_WRITE. Using this lock mode the Cron Jobs behave as follows: When the first job makes the select for update everything goes as expected but the version on the object changes....