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.  [ 1 post ] 
Author Message
 Post subject: parent/child: what if a child can only belong to one parent?
PostPosted: Wed Sep 08, 2004 5:43 pm 
Newbie

Joined: Wed Sep 08, 2004 5:23 pm
Posts: 1
Please bear with me; I've just started with Hibernate...
So maybe this is a stupid question, but here it is anyway:

I just read chapter 16 (the parent/child example) in the docs.
The typical Parent.addChild() method in a one-to-many scenario is implemented like this:

Code:
public void addChild(Child c) {
    c.setParent(this);
    children.add(c);
}


now, if I would do something like this:

Code:
parent1.addChild(c);
parent2.addChild(c);


the collection in parent1 would still contain child c, while the parent-property in the child would contain parent2 as its parent, right?

I wonder what would happen if you persist this state, and whether it is not necessary to remove the child from the previous parent (parent1) before adding it to parent2? Considering the fact that the configuration would contain a one-to-many relationship, I expect that there will be a mismatch between the state in memory and the one in the database?

It's probably so obvious that I just overlooked it, but I'd appreciate it if someone could throw some light on this for me....

Thx,
Andy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.