-->
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.  [ 5 posts ] 
Author Message
 Post subject: one-to-one mapping and unidirectional?
PostPosted: Tue Mar 21, 2006 5:53 pm 
Beginner
Beginner

Joined: Tue Mar 21, 2006 5:49 pm
Posts: 20
I have a book that says one-to-one association needs to be bidirectional, is this correct? Even if I always load from one side of the relation?


Regards,

BTJ

_________________
Someone wrote:
"I understand that if you play a Windows CD backwards you hear strange Satanic messages"
To which someone replied:
"It's even worse than that; play it forwards and it installs Windows"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 5:57 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
this one is answered by my recent example:

http://forum.hibernate.org/viewtopic.php?t=956962&highlight=

No they don't *need* to be bidirectional. The example shows both cases, unidirectional and bidirectional

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 6:10 pm 
Beginner
Beginner

Joined: Tue Mar 21, 2006 5:49 pm
Posts: 20
Forgot to mention that I am using generator class = foreign, and then it looks like I have to add a mapping the other way by addding param name=property>object/> to my mapping file..?

_________________
Someone wrote:
"I understand that if you play a Windows CD backwards you hear strange Satanic messages"
To which someone replied:
"It's even worse than that; play it forwards and it installs Windows"


Top
 Profile  
 
 Post subject: Re: one-to-one mapping and unidirectional?
PostPosted: Wed Mar 22, 2006 9:44 am 
Beginner
Beginner

Joined: Fri Mar 17, 2006 7:30 pm
Posts: 32
bjorntj wrote:
I have a book that says one-to-one association needs to be bidirectional, is this correct? Even if I always load from one side of the relation?


Regards,

BTJ


All depends from which side you are loading. If you are loading in the object that maps to the table with the foreign key, then you only have to do it on that side. If however, you wish to load that object into the object to which that foreign key maps, then you have to do it on both sides. This latter case, though it tends to make more sense in regard to the relationship, feels nothing short of a hack. Perhaps in H4 this will be corrected.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 9:47 am 
Beginner
Beginner

Joined: Fri Mar 17, 2006 7:30 pm
Posts: 32
jt_1000 wrote:
this one is answered by my recent example:

http://forum.hibernate.org/viewtopic.php?t=956962&highlight=

No they don't *need* to be bidirectional. The example shows both cases, unidirectional and bidirectional


Yes, the back and forth discusion jt_1000 and I had shows both how to load from one side only (the relating from side) and how to load from both sides. We also discussed the lack of a way to load from the referring side (the to side) only.

For instance, supposed B relates to A via a foriegn key A_id which points to the PK in A. B can load A into its mapping as one to one. A, however, cannot load B into its mapping without the B having been mapped to load A. This is the part that feels like a hack to me. It is both limiting and short-sighted.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.