-->
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.  [ 2 posts ] 
Author Message
 Post subject: ISession.Update Updates Multiple Objects
PostPosted: Sat Sep 18, 2010 8:21 am 
Newbie

Joined: Fri Sep 10, 2010 12:20 pm
Posts: 3
I have noticed, by using log4net, that when calling ISession.Update, it updates all the changed objects.

For example:
Code:
// Change 2 instances
user1.IsDeleted = true;
user2.UserName = "Xyz";
// Call session.Update to update the 2 users
Session.Update(user1); // This updates both user1 & user2.
Session.Update(user2); // Now there is no need for this

Is this the default behavior of NHibernate or has something to do with my mapping file?
Can I make NHibernate update one by one?

Best regards,
Shehab.

Update:
I not only call Session.Update(user1) however I call Session.Update() followed by Transaction.Commit(). So after the first commit, both objects are updated in the database.
I need only user1 to be updated in the database after the call of first Commit() then user2 by the call of second commit. Can I achieve that?


Last edited by sh_kamalh on Sun Sep 19, 2010 3:44 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: ISession.Update Updates Multiple Objects
PostPosted: Sun Sep 19, 2010 4:17 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
session.Save/SaveOrUpdate/Update are used for (re-)attaching objects to a session. The objects in a session are not saved until the session is flushed. You can do that explicitly with session.Flush() or implicitly in a transaction with transaction.Commit().

In your case, if you already have objects in your session that have been changed, they will be updated in the database together with the objects you explicitly update. If you want to update them separately you either need two sessions or clear the session after the first update (and flush).

_________________
--Wolfgang


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