Hibernate version: 2.1.8
Mapping documents:
Code:
Form 1:
<hibernate-mapping>
<class name="X" table="x">
<id name="id" column="x_id" type="long"/>
<many-to-one name="y"
class="Y"
column="y_id"
unique="true"/>
</class>
<class name="Y" table="y">
<id name="id" column="y_id" type="long"/>
<one-to-one name="x"
class="X"
property-ref="y"/>
</class>
</hibernate-mapping>
Form 2:
<hibernate-mapping>
<class name="X" table="x">
<id name="id" column="x_id" type="long"/>
<many-to-one name="y"
class="Y"
column="y_id"
unique="true"/>
</class>
<class name="Y" table="y">
<id name="id" column="y_id" type="long"/>
<many-to-one name="x"
class="X"
column="x_id"
unique="true"/>
</class>
</hibernate-mapping>
I'm trying to understand what the difference is in modelling a bidrectional one-to-one relationship using the 2 forms above. The first form (<many-to-one> + <one-to-one>) is as described in the manual. Is the second form (<many-to-one> + <many-to-one>) identical functionally to the first, or are there subtle differences? It appears the first form does not use an "x_id" column in Y's table - would this be less efficient than the second form, where X's PK is directly available in Y?
TIA
Nick