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..?
|