-->
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.  [ 2 posts ] 
Author Message
 Post subject: one-to-one unidirectional primary key associations
PostPosted: Fri Oct 22, 2004 12:30 pm 
Newbie

Joined: Fri Oct 22, 2004 11:28 am
Posts: 6
Location: Hertfordshire
Hibernate version:2.1.6

Hibernate supports primary key associations that may be unidirectional (at either end). The Unidirectional mapping files below show this.

However, is it still possible to use the <generator class="foreign"/> to guarantee that when the primary keys are generated they are identical?
Otherwise we have to handle this in the Java object model rather than transparently inside Hibernate.

So far I have seen that if we want to change "assigned" to "foreign" below, the mapping rules force us to add a property and association to the child for the parent, making it bidirectional.

Unidirectional Mapping documents:

Code:
<hibernate-mapping package="test">
   <class name="Person" table="PARENT">
      <id name="parentId" type="long" column="PARENT_ID">
           <generator class="sequence">
            <param name="sequence">PARENTSEQ</param>
         </generator>
      </id>
      <property name="parentName" type="string" column="PARENT_NAME"/>
      <one-to-one name="child" class="Child" cascade="all"/>
   </class>
</hibernate-mapping>


Code:
<hibernate-mapping package="test">
   <class name="Child" table="CHILD">
      <id name="childId" type="long" column="ID">
              <generator class="assigned"/>
      </id>
      <property name="childName" type="string" column="CHILD_NAME"/>
   </class>
</hibernate-mapping>


Bidirectional Mapping for child:

Code:
<hibernate-mapping package="test">
   <class name="Child" table="CHILD">
      <id name="childId" type="long" column="ID">
           <generator class="foreign">
            <param name="property">parent</param>
         </generator>
      </id>
<property name="childName" type="string" column="CHILD_NAME"/>

            <one-to-one name="parent" class="Parent" constrained="true"/>
   </class>
</hibernate-mapping>



Thanks in advance
Ken

_________________
when we set out to write software, we never know enough


Top
 Profile  
 
 Post subject: Same dilemma
PostPosted: Wed Nov 03, 2004 8:10 pm 
Newbie

Joined: Tue Nov 02, 2004 11:44 am
Posts: 8
Gurus, I am facing the same problem. To take advantage of <generator class="foreign"/> , I have to make one-to-one association bidirectional. Is this the only way to go about this?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.