-->
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: Bidir 1-to-1: using <one-to-one> vs 2 x <many-to-on
PostPosted: Sun Mar 06, 2005 10:37 pm 
Newbie

Joined: Sun Mar 06, 2005 10:08 pm
Posts: 3
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


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.