Is it possible to move an entity from one collection to another?
I have two top level entities A and B which both have one-to-many references to another entity C, which happens to have its own network of stuff below it.
Cascade deletes are working fine - if I delete C, it and everything below it goes away. Also, if I delete A or B, then it and its children also go away. So far so good, and I want to keep this cascading behavior.
Now the interesting part.
I want to take C, remove it from A's one-to-many collection and add it to B's one-to-many collection, preserving the object network under C.
a.getChildren().remove( c );
c.setParent(null);
b.getChildren().add(c);
c.setParent( b );
I get errors like "Found two representations of same collection" the moment I do the add().
I'd think this would be a trivial reassignment of some foreign keys, but there seems to be more to the story that I'm missing.
Does Hibernate assume remove() is a delete? The object c is not being orphaned.
Thanks,
-Walt Stoneburner | Hibernate 3.2.5 / Hibernate Annotations 3.3.0.GA