-->
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: Leaving an object Transient
PostPosted: Tue Jun 07, 2005 10:51 am 
Newbie

Joined: Mon Jun 06, 2005 10:33 am
Posts: 6
Hi,

In my project I create an Investment object. I want to keep this object in memory but not to save it to the DB unless the user clicks a 'Save' button.

For some reason, NHibernate decides that the object is dirty and persists it to the DB even before the user clicked the 'Save' button.

I think the reason for this is that right after I create it, I add the Investment object to an Investments bag of a Portfolio object (a kind of "parent" of Investment). I think that when I do that, NHibernate dirties the Investment object.

How can I avoid this? Does this have to do with the cascade value set on the Investments bag in the Portfolio object? Which value is right for me there?

Thanks!
urig

_________________
urig


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 5:01 am 
Regular
Regular

Joined: Tue Mar 15, 2005 12:38 pm
Posts: 73
Location: Bucharest
as far as I know you have 2 options:

1. don't use cascades.
In your example I guess the collection has cascading enabled with some value and this is why, by following the graph, nhibernate considers the it should be saved.

2. evict the object from the session.
I didn't work that much with this feature (so any other opinion whould be appreciated) but you can evict the object from the session in order to inhibit the save. Eviciting as far as I know works for previously persistent object and sets them as detached so you should eveict that "parent" object from the session.

Good luck,
Dragos


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 12:57 pm 
Beginner
Beginner

Joined: Wed Jun 29, 2005 10:40 am
Posts: 30
Location: denver, co
You could also try setting the FlushMode property on your NHibernate session to Never. Normally NHibernate executes a flush at certain points, some of which lead to this sort of confusion. With FlushMode set to Never, you will have to remember to call Flush() yourself when you want something persisted, but you gain more granular control.


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.