-->
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.  [ 5 posts ] 
Author Message
 Post subject: Issue with the use of 2 sessions.
PostPosted: Mon Apr 09, 2007 7:00 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 1:48 pm
Posts: 20
Hibernate version: 3.1.3

Hi,
I am having some problems with the use of 2 different sessions.

Let's say that I have an object that has a property set to the value "1", I retrieve this object in the first session and have it detached.

In another session, I retrieve this same object, set its value to "2" and save it. It works fine.

Then with the dettached object, I want to decrease this value by one. The problem is that I still has this "1" value... And I will get "0" when I save it as it should be 1 (2-1).

How can I sort of 'update' or get the last value from my DB, just before making operations on a detached object?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 09, 2007 11:09 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
http://www.hibernate.org/hib_docs/v3/ap ... ang.Object)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 10, 2007 9:15 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 1:48 pm
Posts: 20
Thx !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 11, 2007 4:40 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 1:48 pm
Posts: 20
The answer is good and resolved my problem... however, I am now dealing with another problem...

In session1, I have a member updating his data within a JSF application, in this 'member object', there is a 'credit' attribute which is set for instance to 10.

AT THE SAME TIME, in another session, the admin is updating this same user's data and sets this credit attribute to 15...

If the admin validates and saves the data (through Hibernate), then when the user validates his page, it will overwrite those updates with his own previous values, ie 10 for the credits! Is there a way to avoid this? Can the value 15 be kept since it is newer than the '10' (that has not changed in the user's session)?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 11, 2007 9:00 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
http://www.hibernate.org/hib_docs/v3/re ... optimistic

Section 11.3.2. I highly recommend number-based versioning, but you can use timestamps also which some find more helpful. It's very simple to enable, just use the "version" feature on an int property. Be sure to read the whole chapter, though, so you understand the semantics of concurrency and the issues surrounding it.

-Chris


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