-->
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.  [ 3 posts ] 
Author Message
 Post subject: Navigability and foreign key
PostPosted: Mon Sep 26, 2005 2:41 pm 
Newbie

Joined: Mon Aug 08, 2005 4:16 pm
Posts: 15
Hi,

If I have two entities, say Location and Address, with a one-to-one relation, is there any way I can make the relation uni-directional from Location to Address, if the foreign key is on the ADDRESS table and not the LOCATION table.

The only way I can get it working is to have the ADDRESS_ID column in the LOCATION table. If I have the LOCATION_ID column in the ADDRESS table, I am not able to define a uni-directional relationship from Location to Address.

Any help would be highly appreciated,

Ta
Abu Mariam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 2:01 pm 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
I didn't find a direct way to reach what you want (but though I'm quite experienced I wouldn't claim that I didn't miss "the simple solution"). The solution I found uses a set with one element.

The mapping would look as follows:
Code:
<class name="Location" table="LOCATION" lazy="false">
    <id name="id" type="java.lang.Long" column="WIDGET_ID" unsaved-value="null">
        <generator class="native"/>
    </id>
    <set name="address" cascade="all" access="field">
      <key column="LOCATION_ID" not-null="true" unique="true"/>
      <one-to-many class="Address" />
    </set>
</class>
<class name="Address" table="ADDRESS" lazy="false">
    <id name="id" type="java.lang.Long" column="WIDGET_ID" unsaved-value="null">
        <generator class="native"/>
    </id>
</class>

Note that the key column is declared unique, which garanties the one to one relationship.

In Location you could hide the fact that you're actually using a set by writing the getter and setter that hide the operations on the set and return an Address object.

Was the best I could - hope this helps you :-)

Erik


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 2:20 am 
Newbie

Joined: Mon Aug 08, 2005 4:16 pm
Posts: 15
Thanks Erik. I did consider this as a solution.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.