-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Are @Version fields loaded implicitly?
PostPosted: Mon Jun 13, 2011 10:20 pm 
Newbie

Joined: Mon Dec 28, 2009 10:56 pm
Posts: 5
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.