-->
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: composite-id and foreign key mapping with one-to-one
PostPosted: Tue Feb 15, 2005 12:43 pm 
Newbie

Joined: Tue Feb 15, 2005 10:09 am
Posts: 5
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.


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.