The update actually should be rollback in the transaction, however, it is commit in another transaction. Then I add a select after the update, and rollback the transaction, this time it is really rollback!! What going on? Please help! I am using Oracle.
Below capture the system flow (In the same session):
Code:
session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
//select the object by lock PESSIMISTIC_WRITE
Query query = session.createQuery(SQL);
query.setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE));
object = query.list().get(0);
session.update(object);
tx.rollback();
tx = session.beginTransaction();
tx.commit() //this commit the update in the above tran!!
tx = session.beginTransaction();
//select the object by lock PESSIMISTIC_WRITE
...
session.update(object);
//select the object by lock PESSIMISTIC_WRITE
...
tx.rollback();
tx = session.beginTransaction();
tx.commit() //this time the update in the above tran do not commit to DB!!
session.close();