-->
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.  [ 6 posts ] 
Author Message
 Post subject: Optimistic Locking w/o Versioning
PostPosted: Sun Jun 20, 2004 8:13 pm 
Newbie

Joined: Sun Jun 20, 2004 8:09 pm
Posts: 2
I'm presently working on the development of a persistence layer for a legacy database system. The layer must implement optimistic locking, and as in section 10.4.2 of the reference manual, each interaction with the persistent store must occur in a new Session with the same persistent instances. Unfortunately, due to a number of constraints, I cannot modify the database to add a version column. Section 5.1.3 of the manual states that the version option is "the only strategy that correctly handles modifications made outside of the session," ruling out my idea of checking all the columns for modifications. Would I be correct in assuming that any snapshots made are discarded when a Session is closed? If so, is it possible (and sensible) to extract the snapshot and store it for use in a new Session? Any other ideas? I like Hibernate and hope I can work this out.

Thanks in advance!

-Joe


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 20, 2004 9:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use optimistic-locking="all" or optimistic-locking="dirty" with select-before-update="true"


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 9:11 am 
Newbie

Joined: Sun Jun 20, 2004 8:09 pm
Posts: 2
Perhaps I am missing something, but based on my understanding of the reference guide (section 5.1.3, containing the quote from my original post), optimistic-locking="all" or "dirty" cause issues when modifications are made outside the session. The reference also says that select-before-update basically only checks whether you have modified data before performing an update, but the system would not know if someone else modified the data between sessions (would it?). How does your solution handle the following case:
Code:
// foo is an instance loaded by a previous Session
foo.setProperty("bar");
session = factory.openSession();
session.update(foo);
session.flush();
session.connection().commit();
session.close();

...if someone else has modified the data between when foo is loaded and when the new session is opened?

Sorry if I am just misinterpreting the reference, as I am still not entirely sure why it recommends against optimistic-locking="all" or "dirty" when modifications are made outside of the session.

Thanks again,
-Joe


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 10:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
select-before-update="true" basically allows the session to compare the object you pass in to the database state, so it can use optimistic-locking="dirty" or "all" even when the object was detatched.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 12:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually, thats not true (I think I told you it was true, and I was wrong). select-before-update would fetch a current snapshot. For optimistic locking you would need to know the old snapshot, which is impossible.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 12:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Ah okay, I see ... so there is no way to do optimistic-locking without a version column when using detatched objects.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.