-->
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: Update childs
PostPosted: Fri Oct 14, 2005 12:08 pm 
Newbie

Joined: Fri Oct 14, 2005 12:02 pm
Posts: 1
I`ve got a one to many relation in my class

<bag name="CustomersLocations" lazy="true" inverse="true" cascade="all-delete-orphan" >
<key column="CustomerID" />
<one-to-many class="SET.Common.Tables.CustomersLocation, SET.Common" />
</bag>

In my code I want to update childs relation by creating a new arraylist and assigning it to parent


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 15, 2005 3:56 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
You should not be assigning a new collection to replace the old one. If you retain the collections that NHibernate gives you, it can be aware of changes. I think what you might want to do is:
Code:
myFoo.CustomersLocations.Clear();
foreach( CustomersLocation location in newChildObjectCollection )
{
    myFoo.CustomersLocations.Add( location );
}
session.Save( myFoo );

The Clear() call should mark all the old records to be deleted, so any that you Add() will be all that's left. If there's a better way, I'd love to hear it, but this is what I've done in the past.


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.