Hi,
I did read the chapter on parent/child relationship but could not find much help.
I have a parent/child relationship with a <bag> and inverse=true.
I can add a parent with children like below.
session.save(parent);
parent.setParent(); // set parent for all children objects
session.update(parent);
Problem is that when I update the parent, the children are duplicated (in other words, old children are not removed).
My GUI has a table/grid where user can add/update/delete children. So, I thought I could just use parent.setChildren(List children) and hibernate will take care of removing the old children but that didn't work.
I also tried by explicitly removing the children as
parent.setChildren(new Vector()); // to clear old children
session.save(parent);
parent.setChildren(updatedChildren);
session.save(parent);
but the problem is still there. I AM using cascade='all'. I just can't get rid of old children with this code. Hopefully I dont have to iterate over old children and call session.delete on all children.
Please let me know if I am doing anything wrong here.
_________________ Thanks,
Tahir
|