I am using Hibernate to connect to a Postgres DB on Windows. I am using optimistic locking in my app, but there is one object for which I need pessimistic locking. I am trying to use the code below:
Code:
public boolean getLock(Object o)
try
{
session.lock(o, UPGRADE_NOWAIT);
return true;
}
catch (Throwable t)
{
LOG.error("Object is already locked");
return false;
}
I thought that the session.lock() would throw an exception if the persistent object was already locked. But when I run my tests, the calls to session.lock() wait until the other code thread commits the transaction that got the original lock on the object.
Any clue to what I might be doing wrong, or what I'm misunderstanding?
Thanks,