Hibernate version:3 beta4
Hi,
I've been having problems mapping following relationship.
Parent mapping:
<hibernate-mapping>
<class name="somepackage.Parent" table="PARENT">
<id name="parentId" type="java.lang.String" column="parent_id" unsaved-value="null" >
<generator class="sequence">
<param name="sequence">next_parent</param>
</generator>
</id>
<set name="children" table="child1" lazy="true" inverse="true" cascade="all-delete-orphan" >
<key column="parent_id"/>
<one-to-many class="somepackage.Child1"/>
</set>
</class>
</hibernate-mapping>
Child1 mapping:
<hibernate-mapping>
<class name="somepackage.Child1" table="child1" >
<composite-id name="childKey" unsaved-value="any" class="somepackage.ChildKey" >
<key-property name="childId" type="java.lang.Integer" column="child_id"/>
<key-many-to-one name="parent" class="somepackage.Parent" column="parent_id" />
</composite-id>
<one-to-one name="child2" class="somepackage.Child2" />
</class>
</hibernate-mapping>
Child2 mapping:
<hibernate-mapping>
<class name="somepackage.Child2" table="child2" >
<composite-id name="childKey" unsaved-value="any" class="somepackage.ChildKey" >
<key-property name="childId" type="java.lang.Integer" column="child_id"/>
<key-many-to-one name="parent" class="somepackage.Parent" column="parent_id" />
</composite-id>
<one-to-one name="child1" class="somepackage.Child1" constrained="true" />
</class>
</hibernate-mapping>
Child1 and Child2 have a one-to-one relation and I would like to manage the relation so that when child1 is removed from parent, child2 is also removed, and I can remove child2 without removing child1. But with this configuration when I remove the child2 reference from child1 hibernate doesn't delete the record from child2 table.
I've tried a several different things over period to get this to work without any luck. Also is it possible to map the child2 as following :
<id name="childKey" type="somepackage.ChildKey" >
<column name="child_id" />
<column name="parent_id" />
<generator class="foreign" >
<param name="property" >child1</param>
</generator>
</id>
Since we are dealing with a legacy database we don't have the luxury to modify the schema, we have to make it work the way it is, so any suggestions will be greatly appreciated.
Thanks.
|