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