-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need a clarification on Optimistic Locking
PostPosted: Tue Aug 03, 2004 6:38 pm 
Newbie

Joined: Tue Aug 03, 2004 5:42 pm
Posts: 16
I simply need some minor clarifications, I am not running code yet. Hope someone will oblige:
    First, how does the programmer indicate to Hibernate that he wants to use Optimistic Locking? I mean, at some point, Hibernate must check versions right? My understanding is that when a session is disconnected and reconnected, all objects in Session cache are automatically version verified by Hibernate. Is this correct?

    When one module of code queries and retrieves some objects, they get put into the Session cache, right? Now when, as part of the same Transaction and same Session with no intervening disconnect/reconnects, another module of code queries and retrieves some objects, and some objects in the second query have the same database identity as objects in the first query, what guarantee is that their versions havent changed in between the queries? My understanding again here is that if there are no intervening disconnects, then by default read locks would already have been placed intelligently by Hibernate (assuming that the isolation level was correctly set) during the first query and hence the second query would return the same versions of objects with matching database identities. Is this correct? And if there were an intervening disconnect/reconnect, then at reconnect time version mismatches would show up. Is this correct?



Thank you very much in advance, I really need to understand this well..

Sundeep


Top
 Profile  
 
 Post subject: Re: Need a clarification on Optimistic Locking
PostPosted: Mon Aug 16, 2004 8:48 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
sundeepprakash wrote:
I mean, at some point, Hibernate must check versions right? My understanding is that when a session is disconnected and reconnected, all objects in Session cache are automatically version verified by Hibernate. Is this correct?

add a <version> or <timestamp> tag into your mapping. That's all.
The version is checked for every updates

Quote:
When one module of code queries and retrieves some objects, they get put into the Session cache, right? Now when, as part of the same Transaction and same Session with no intervening disconnect/reconnects, another module of code queries and retrieves some objects, and some objects in the second query have the same database identity as objects in the first query, what guarantee is that their versions havent changed in between the queries?

1. Your tx isolation
2. the update where version=? made by hibernate when flushing

_________________
Emmanuel


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

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.