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.
<hibernate-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> </id> <!-- some properties here --> <set name="children" cascade="all,delete-orphan" access="field" table="child"> <cache usage="read-write"/> <key column="parentid" not-null="true"/> <one-to-many class="Child"/> </set> </class> </hibernate-mapping>
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();