-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Parent-child Persistence
PostPosted: Wed Feb 28, 2007 4:05 pm 
Newbie

Joined: Wed Feb 28, 2007 3:24 pm
Posts: 1
Hi..

I am trying to a save a parent-child relationship in Hibernate 3.2

I have created my mappings, DAO & POJO classes using HBT 3.2.8.

In the parent mapping xml, I have set child to cascade="save-update".
Also all the foreign key mapping in the parent are also set with cascade="save-update".

In the child, the parent occurs as a foreign. hence the <many-to-one> property for the parent in child mapping xml is also set with cascade="save-update".

So you have

Mapping For Parent,
---------------------------------
<hibernate-mapping>
<class name="com.sysadmin.hibernate.Parent" table="PARENT" schema="DB2ADMIN" lazy="false">
<many-to-one name="someForeignKey" class="com.sysadmin.hibernate.ForeingKey" fetch="select" cascade="save-update">
<column name="FOREIGN_KEY_ID" />
</many-to-one>
<set name="children" inverse="true" lazy="false">
<key>
<column name="CHILD_ID" not-null="true" />
</key>
<one-to-many class="com.sysadmin.hibernate.Child" />
</set>
</class>
</hibernate-mapping>

Mapping For Child
----------------------------------------------
<hibernate-mapping>
<class name="com.sysadmin.hibernate.Child" table="CHILD" schema="DB2ADMIN" lazy="false">
<many-to-one name="parent" class="com.sysadmin.hibernate.Parent" fetch="select" cascade="save-update">
<column name="PARENT_ID" />
</many-to-one>
</class>
</hibernate-mapping>

The parent-child persistence is happening inside a transaction.

When Hibernate tries to save the child, it gives the PropertyValueException. indicating that there is a not-null property references a null or transient value.

For some reason, the parent object in child is still transient..

Can you please explain this..?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.