-->
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.  [ 3 posts ] 
Author Message
 Post subject: Reload after evict
PostPosted: Mon Jan 19, 2009 7:09 am 
Newbie

Joined: Fri Jan 16, 2009 4:54 am
Posts: 2
Hibernate version:
Hibernate 3.0

How can I reload an object which exist in my current session and
has a version attribute to manage optemistic lock.

I try to detach the object with evict() from the current session
and reload the object with load(). But I got a StaleObjectStateException.

Best Regard
M.Schäfer


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 7:50 am 
Regular
Regular

Joined: Tue Jun 03, 2008 1:12 pm
Posts: 84
Location: germany
evict detaches the instance by deleting it from the session-cache!

So you can not say evict and load.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 11:12 am 
Newbie

Joined: Tue May 06, 2008 8:01 am
Posts: 4
I don't understand your answer?

Simple sample without showing session creation and the transaction management !

s1.save(o1);

o2 = s2.load(o1.getId());

o1.setNewValue(...);
s1.saveOrUpdate(o1) ok!, now database has a new version


o2.setNewValue(...);
s2.saveOrUpdate(o2) here I got the stale exception


To solve the collison I call :


s2.evict(o2);
o3 = s2.load(o2.getId()); here I got the stale exception object

I don't no why I got the stale exception, because I have released the object o2 from s2. So o2 is detached and doe'snt exist in the session s2.


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