-->
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: addChild in bidir. one-to-many incomplete?
PostPosted: Fri Nov 04, 2005 3:35 pm 
Newbie

Joined: Wed Aug 10, 2005 5:03 am
Posts: 4
Reading refernce docs at:
http://www.hibernate.org/hib_docs/v3/re ... hild-bidir

I'm wondering whether the following method is incomplete:
public void addChild(Child c) {
c.setParent(this);
children.add(c);
}

What if Child c already had a parent? After the method we will have two Parents with children arrays both referencing Child c, although c will only point to the newer Parent. Shouldn't the method be:

public void addChild(Child c) {
Parent oldParent = c.getParent();
if(oldParent != null)
{
oldParent.remove(c);
}

c.setParent(this);
children.add(c);
}


thanks
-nikita


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 05, 2005 6:00 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
IMHO addChild should not remove the child from anything. If you want to move a child from one parent to an other first call removeChild and then addChild or create a new method called moveChild.

HTH
Ernst


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.