Under Hibernate 2.1.5 and 2.1.6 against Oracle 9.2.0 (via Oracle9Dialect), it seems that executing an HQL query with a lock mode set on a column alias via setLockMode("alias", LockMode.UPGRADE) doesn't actually mark the object as UPGRADEd in the session, at least in conjunction with joins. It
does remember to put "for update" on the SQL though.
So something like this:
Code:
String MY_HQL
= " select foo "
+ " from com.dmlloyd.Foo foo "
+ "inner join fetch foo.bar bar "
+ " where foo.id = ? ";
Query q = session.createQuery(MY_HQL);
q.setLockMode("bar", LockMode.UPGRADE);
q.setLong(0, 1234);
Foo foo = q.uniqueResult();
LockMode currentMode = session.getCurrentLockMode(foo.getBar());
if (currentMode.lessThan(LockMode.UPGRADE)) {
throw new RuntimeExcpetion("Barf: " + currentMode);
}
would end up showing: "Barf: READ" even though the object is locked in the database (and then some... I couldn't get Hibernate to do FOR UPDATE OF; even modifying Oracle9Dialect to return true for supportsForUpdateOf() didn't do it, so it just used a blanket FOR UPDATE across the join).
Any ideas?