Joined: Fri Jun 04, 2004 7:22 pm Posts: 8 Location: Phoenix, Arizona
|
Hi,
I would like to know the implementation for the following scenario.
Creating parent dynamically in the database and attach the children.
I have found the following code in hibernate site. Here, parent is already created and the child link is attached to it. But , my case is parent should be created in the database dynamically and then child needs to be attached. I am using sequence for generate the unique id for parent and child. My parent has only the field "id" which is generated dynamically. My child has other information with parent id as a foreign key.
<many-to-one name="parent" column="parent_id" not-null="true"/>
<set name="children" inverse="true">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>
Parent p = (Parent) session.load(Parent.class, pid);
Child c = new Child();
c.setParent(p);
p.getChildren().add(c);
session.save(c);
session.flush();
Please do the needful.
Thanks a ton in advance.
|
|