-->
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: one-to-many using alternate keys --- this seems to work
PostPosted: Sun Jul 02, 2006 5:58 pm 
Newbie

Joined: Thu Aug 05, 2004 6:01 pm
Posts: 18
Location: New Zealand
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.13


<hibernate-mapping>

<class name="hibernate.mysql.bo.Parent" table="parent">

<id name="id" column="id" unsaved-value="null">
<generator class="increment"/>
</id>


<version name="version" column="version" type="long"/>

<properties name="alternateKey">
<property name="id" column="id" type="long" insert="false" update="false"/>
<property name="otherId" column="other_id" type="long"/>
</properties>

<set name="children" lazy="false" cascade="all-delete-orphan" inverse="true">
<key not-null="true" property-ref="alternateKey">
<column name="parent_id"/>
<column name="parent_other_id"/>
</key>
<one-to-many class="hibernate.mysql.bo.Child"/>
</set>

</class>

<class name="hibernate.mysql.bo.Child" table="child">

<id name="id" type="long" column="id" unsaved-value="null">
<generator class="increment"/>
</id>

<version name="version" column="version" type="long"/>

<property name="name" column="name" type="string"/>

<many-to-one name="parent" property-ref="alternateKey">
<column name="parent_id"/>
<column name="parent_other_id"/>
</many-to-one>

</class>

</hibernate-mapping>





I have been looking at mapping a one-to-many relationship using alternate keys. The above mapping seems to work for the situation where the database tables are as such:

PARENT
id
version
other_id


CHILD
id
version
name
parent_id
parent_other_id

How does this look?

Cheers
Shane


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.