How can I move a child of a privately owned collection to a new parent?
415279Jan 11 2005 — edited Jan 14 2005I have a recursive tree and want to implements a "move to" operation.
I.e. changing the parent reference and adding the node to the privately owned list of children of the new parent.
1: newParent.children.add(moveChild);
2: oldParent.removeChild(moveChild);
3: moveChild.setParent(newParent);
That gives me the right data in the TopLink cache for the UI. However, when I commit the UnitOfWork, the moveChild
is deleted persistently in the second line (privately owned collection). If I comment out the 2nd line, the commit works non-destructively, but the child is with both, the old and the new parent, and the UI is messed up.
[ The reason for keeping the children privately owned is that child and parent are a composite pattern and of the same class. So if I delete a top-node parent, it would cascade-delete the whole tree and with "private collection" TopLink could figure out the right delete order. At least that what I believe so far].
Has anybody had this problem before?