I am having an issue using LockMode.UPGRADE.
My code looks like;
MyObject a = getObject(criteria, LockMode.UPGRADE);
a.incrementCount();
commitTransaction();
What appears to be happening is that several machines/threads try to access the object at once. Thread1 gets the lock. It increments the count from 1 to 2 and commits. Then the second thread gets the lock, but its copy of the object still has count 1. So after it increments the count is still 2, but I want it to be 3. Is thread2 getting the object from a cache? I thought with LockMode.UPGRADE hibernate would bypass the cache?
What am I missing/misunderstanding and what is the correct fix - should I call refresh right after the call to getObject?
TIA
|