Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   when save parent, the children do not get saved. URGENT PLEASE. (http://www.go4expert.com/forums/save-parent-children-saved-urgent-t7045/)

leela1 26Oct2007 00:44

when save parent, the children do not get saved. URGENT PLEASE.

I have a question and it could be a very simple/silly question for you. Please reply back to my post immediately as soon as possible. Please treat this as very urgent. Thanks a lot for the help in advance.

When I save a parent, the children do not get saved, unless i save them independently. Is there anyway that i can bypass saving children independently? I just wanted to make one call to save parent which should take care of saving children as well. please guide me. This is a unidirectional one-to-many mapping.


<class name="Parent" lazy="true" proxy="Parent" table="parent">
<cache usage="read-write"/>
<id name="id" access="field" type="long" >
<generator class="MyGenerator"></generator>
<!-- some properties here -->
<set name="children" cascade="all,delete-orphan"
<cache usage="read-write"/>
<key column="parentid" not-null="true"/>
<one-to-many class="Child"/>

here is the code :


Session session1 = sf.openSession();
Parent parent1 = (Parent )session1.load(Parent.class, 123);
parent parent2 = new Parent(parent1);
session1 .flush();
Session session2 = sf.openSession();
session2 .save(parent2);
session2 .flush();

Please let me know what is wrong here. Thanks a lot.

All times are GMT +5.5. The time now is 20:43.