-->
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 in multiple sessions
PostPosted: Tue Oct 21, 2003 6:15 pm 
Newbie

Joined: Fri Oct 17, 2003 12:40 pm
Posts: 16
I have implemented Optimistic Locking; it works in one environment and not in other.
In my test case, I load 2 objects using the same id. Initially the version number in the database is 0. I make changes to both first and second object. I saveOrUpdate the first object it works fine, and the version number is updated to 1. When I saveOrUpdate the second Object, I get StaleObjectStateException. It works perfectly.
The problem is in the web environment, I open the same page on two machines. The pages load the same Object. Initially the version number is 0. I make changes to both the pages. I save the first page, it saves and the version number is updated to 1. Now, I save the second page. I excepted a StaleObjectStateException. But I don't get the error. The second save overrides my first change. The version number is also updated to 2.
Does this situation call for a manual check in the version number before the saveOrUpdate? How is the second save able to override the first save and even update the version number?

Please provide your input.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 6:26 pm 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
where are you storing the hibernate session and are you using thread local or open in session in view pattern?

_________________
Mauricio Hern


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 11:41 pm 
Newbie

Joined: Fri Oct 17, 2003 12:40 pm
Posts: 16
A new session is created before interaction with the datastore, then all the required operation(s) are performed, then the session is flushed, commited and closed. Only the optimistic locking is not working, everything else is working fine.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 9:47 am 
Newbie

Joined: Fri Oct 17, 2003 12:40 pm
Posts: 16
Can somebody from hibernate team help me on this issue.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 9:59 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You have a bug somehwere in your code.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 10:34 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
To be more verbose than Christian, either:
- your code use the same opened session
- your code read the second state AFTER the commit of the first one.
- version property is kind of broken during your presentation layer trip

_________________
Emmanuel


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.