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