Pages

Monday

Hibernate - The Concurrency Issue

Be careful when using session.lock(object, LockMode.UPGRADE);
The best practice is to check the object whether if it's already locked with
UPGRADE mode.
public void selectForUpdate(Object object) {
if (getSession().getCurrentLockMode(object) !=
LockMode.UPGRADE) {
getSession().refresh(object, LockMode.UPGRADE);
}
}
Because if an object is already locked, locking it again will release the
previous locking.

No comments:

Post a Comment