I exchange id's between two objects with own collections. But I can't find success method.
I think, while I before exchange evict my objects and collections and then remove objects and save these again, the Hibernate remove collections but not remove objects.
Code:
//from new sesstion
Parent tp = (Parent) sess.load(Parent.class, new Long(1));
Parent tp1 = (Parent) sess.load(Parent.class, new Long(10));
// evict parent
sess.evict(tp);
sess.evict(tp1);
// ... and List
for(int i=0; i<tp1.getChilds().size(); i++) sess.evict(tp1.getChilds().get(i));
for(int i=0; i<tp1.getChilds().size(); i++) sess.evict(tp1.getChilds().get(i));
// delete parents (from DB?)
sess.delete(tp);
sess.delete(tp1);
// save parents with new id's
sess.save(tp, new Long(10));
sess.save(tp1, new Long(1));
......
//later from new sesstion
Parent tp = (Parent) sess.load(Parent.class, new Long(1));
Parent tp1 = (Parent) sess.load(Parent.class, new Long(10));
// Lists are lost !!!!!!!!!!!!!!!!!
tp.getChilds().size() == 0 !!!!!!!!!!!!!
tp1.getChilds().size() == 0 !!!!!!!!!!!!!