-->
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: temporary remove of object from persistent state
PostPosted: Thu Oct 26, 2006 6:05 am 
Newbie

Joined: Fri Jul 28, 2006 4:32 am
Posts: 9
Hello, I'v got this scenario in my aplication. I load object from DB (through hibernate) and now I want to do some operation above this object, like change his state (atributes) etc. And then when I call method Save() everything is saved to DB otherwise I don't want to do anything (then I reload this oj from DB and obtain previous state of attributes of object).

How to do that? Because when I change any attribute(property) persisted object then Hibernate automatically save this changes to DB - how to remove object from persistent state (and prevent NHibernate to save it to DB automatically) for a while and after some operation to load it back?

Thx a lot for your answer.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 8:27 am 
Regular
Regular

Joined: Tue Jan 03, 2006 11:43 am
Posts: 51
Location: Sweden
What you want is called evicting object.
On the ISession there is a method Evict() that you can use for this.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 5:48 am 
Newbie

Joined: Fri Jul 28, 2006 4:32 am
Posts: 9
Thanks a lot. But I still have same problem. Which command can cause loading of object back to hibernate cache (opposite of Evict() cmd) ?
Strange is that only some attributes of my object are saved into DB and on other hand some don't (although they are changed [in memory]).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 7:39 am 
Regular
Regular

Joined: Tue Jan 03, 2006 11:43 am
Posts: 51
Location: Sweden
The opposite is Lock() or Update(). The difference between them is that Lock() will not make an update to the database, but both of them bring the object back to the session cache.

When you evict/update/save/delete something it will only go as far as you specified by the cascading property in the mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 10:17 am 
Newbie

Joined: Tue Oct 24, 2006 2:51 pm
Posts: 19
Consider also using SaveOrUpdate() and SaveOrUpdateCopy if

1) The disconnected tier may send a NEW object back, eg. a object that was not extracted from the store
NHibernate is smart enough to know (based on usaved-value="" in mapping) if the object is to be saved or updated
Another one is to use version control or timestamps

SaveOrUpdateCopy() goes further : reconnect the object, look if has to be updated or saved and...if you have an instance loaded in the CURRENT (say it, Business Facade tier) session, that one wil be automatically updated (in memory!!)

NHibernate is great :-)


Top
 Profile  
 
 Post subject: Re: temporary remove of object from persistent state
PostPosted: Mon Jan 31, 2011 5:15 am 
Newbie

Joined: Mon Jan 31, 2011 4:49 am
Posts: 6
hi

you don't need to remove it from nhibernate session

you can just do this after you change attribute

session.Refresh(Object);

and the object is refreshed from database

and return as it was.


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.