imchi wrote:
I am trying to re-assign all children from Parent p1 to Parent p2:
[... get all children from p1 ..]
child1.setParent(p2);
child2.setParent(p2);
[ .. etc. ..]
hibernateTemplate.saveOrUpdate(p1);
Also, I clear the map in p1 that contains child1, child2, etc.
Then, I need to delete p2 because it is empty now (no children):
hibernateTemplate.delete(p1);
hibernateTemplate.flush();
I am confused here - you are moving them from p1 to p2, so wht would you want to delete p2? Secondly I would not saveOrUpdate p1 until you have removed the children from p1 which you don't appear to have done. The process would be as follows:
1) Get all children of p1
2) remove each child (or the collection) from p1
3) remove the parent reference in each child from p1 and change to p2
4) set each child to reference p2
5) save/update/delete (if you want to) p1
6) save/update p2
Or have I missed something here?
Good luck!
S[/list]