Is it must to do insert of new parent with childs in 2 steps?
1. save(parent) - retrieve generated parentId
2. saveOrUpdate(parent) - add childs to parent and save it
one-to-many mapping
Code:
<set name="children" inverse="true" cascade="all-delete-orphan">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>
Because code below is not working properly. Because table for Child object have parentId null at the end of code:
Code:
Parent p = new Parent();
Child c = new Child();
c.setParent(p);
p.getChildren().add(c);
session.saveOrUpdate(p);
Code in two steps (this code not fit to session facade):
Code:
Parent p = new Parent();
session.saveOrUpdate(p);
session.flush();
Child c = new Child();
c.setParent(p);
p.getChildren().add(c);
session.saveOrUpdate(p);
Problem with insert in two steps is, that I would like to have SessionBean, that have method store(Parent parent), and I would like to send new parent object together with it's childs to session bean.
Any help how to do it in multitier environment?
Thanks very much.