-->
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: HiA: The easiest way to represent a 1:1 assoc. is *:1, why?
PostPosted: Wed Aug 09, 2006 5:15 am 
Newbie

Joined: Wed Aug 09, 2006 4:57 am
Posts: 3
From Hibernate in Action:

"The easiest way to represent the association from User to its billingAddress (a one to one association) is to
use a <many-to-one> mapping with a unique constraint on the foreign key. This may
surprise you, since many doesn’t seem to be a good description of either end of a
one-to-one association! However, from Hibernate’s point of view, there isn’t much
difference between the two kinds of foreign key associations."

In fact this surprise me, what are the advantages of use many-to-one instead one-to-one, many-to-one need one more attribute (unique="true") and one-to-one tend to be more intuitive for future reviews (many-to-one may confuse another developers, just like me)

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 5:45 pm 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
I was thinking the same thing myself the other day, when designing some tables.

I have an article table, a usedArticle table and bunch of tables with specific codes for each usedArticle.

I can either put the bunch of foreign keys in usedArticle
(The result is 1:1 relation which is nice, the downside is the let us say 50 columns of unused data, since each usedArticle only needed one set of codes)

or I can put a foreign key to usedArticle in the bunch of tables.
(the downside beeing a indirect 1:1 relation - its really a M:1 relation with a unique constraint - which isn't that nice, but you don't get the 50 unused columns in usedArticle which IS nice)

hope that explains why you would use a M:1 relation when it looks like a 1:1 relation :)


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.