-->
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.  [ 7 posts ] 
Author Message
 Post subject: Evicting objects from the session
PostPosted: Thu Aug 25, 2005 5:46 pm 
Newbie

Joined: Thu Aug 25, 2005 5:33 pm
Posts: 10
Hi,

I have a question about hibernate detached instances, and then re-attaching them.

My simplified sequence of events is:
1) Get the object from the database
2) Update the object
3) Detach the object from the session via the evict() method

At this point I would like to re-attach the object back to the session - is this possible?


thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 6:06 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#objectstate-detached


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 8:22 pm 
Newbie

Joined: Thu Aug 25, 2005 5:33 pm
Posts: 10
Thanks for the link, and I understand how the update method can be used.

However, I also want to re-attach the detached object to the session without performing any transactions, ie SQL updates, etc. My detached object will be different from its database representation, so this means that I cant use the lock() method. Is there any other way of doing this?

thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 3:02 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
May I ask what needs to be done that requires you to evict the object in the first place? Why can't it be in persistent state the whole time?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 9:59 am 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Why do you care if it gets re-attached to a session if you don't want any SQL updates to occur? If the object has changed, you use update() to persist the changes. If you don't want to persist the changes, why re-attach it?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 10:10 am 
Newbie

Joined: Thu Aug 25, 2005 5:33 pm
Posts: 10
Nathan,
the reason is because I want to walk to object graph, and to do that the object needs to be associated to the session. Given that I may be walking the object graph in a stuts action (where no transaction is open) I cant use update().


Dennis,
Due to legacy reasons we use an interceptor to convert objects that are displayed in the JSPs to hibernate objects. If this object stays persistent it then means the web-tier (struts actions) and services layers are dependent on this interceptor. which I would prefer not to be the case.



thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 12:18 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Well, if the object has been modified, Hibernate has to sync those changes up with the database in order to be able to work with that object. It has no other way of knowing what has changed.

If you need to walk the object graph and can't update(), you have to pre-initialize the graph so that it's all loaded before detaching.


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