Hi guys,
Thanks for the great work you do on Hibernate!
I have encountered some behaviour and wanted to validate it before opening a JIRA. In the
User Guide it says:
"If Session.load() is called with UPGRADE or UPGRADE_NOWAIT, and the requested object was not yet loaded by the session, the object is loaded using SELECT ... FOR UPDATE... Session.lock performs a version number check if the specified lock mode is READ, UPGRADE or UPGRADE_NOWAIT"
So I take this to mean (and what seems to happen is), if I just try and LockMode.UPGRADE an unloaded object (that uses @Version) I see:
Code:
select a from Foo where a.id = ? for update
But if I try on an object I have already loaded I see:
Code:
select a from Foo where a.id = ? and a.version = ? for update
I take this to mean that because Hibernate has loaded the version earlier, it can check against it. So far so good. What seems strange is if, in a different scenario, I just load a single field from an object:
Code:
select a.name from Foo where a.id = ?
And then try and LockMode.UPGRADE it, I still see:
Code:
select a from Foo where a.id = ? and a.version = ? for update
So Hibernate must have loaded the version implicitly (in order to be able to do version=)? Is this expected?
Regards,
Richard.