-->
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.  [ 6 posts ] 
Author Message
 Post subject: P 283 why is it many-to-one on the User end?
PostPosted: Mon Sep 03, 2007 11:41 pm 
Newbie

Joined: Tue Nov 25, 2003 11:49 pm
Posts: 12
Couple of questions...

The authors don't explain satisfactorily why they use many-to-one on the User end when they have a 1->1 relationship b/w User and Address.

Secondly,

Are you saying that when you have an optional 1->1 relationship you should always use a jointable?

Where's the example that shows nullable foreign keys and why isn't that approach preferable?

JPA annotations are a lot easier to understand as it's @OneToOne on both sides.


Top
 Profile  
 
 Post subject: Re: P 283 why is it many-to-one on the User end?
PostPosted: Tue Sep 04, 2007 1:26 am 
Newbie

Joined: Tue Nov 25, 2003 11:49 pm
Posts: 12
Ok now I get it. one-to-one only applys to the shared primary key approach and that when you want to use the foreign key approach you have to use many-to-one. with a unique constraint.

let me just say that that's is quite confusing and that since the relationship is conceptually one-to-one it should be one-to-one regardless of how you choose to physically model it and add attributes to differentiate b/w shared primary key and foreign key approaches.

I should not have to use an identifer that suggests a completely different cardinality to what I'm modelling.

IMHO.

steffi1 wrote:
Couple of questions...

The authors don't explain satisfactorily why they use many-to-one on the User end when they have a 1->1 relationship b/w User and Address.

Secondly,

Are you saying that when you have an optional 1->1 relationship you should always use a jointable?

Where's the example that shows nullable foreign keys and why isn't that approach preferable?

JPA annotations are a lot easier to understand as it's @OneToOne on both sides.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 1:30 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
The authors don't explain satisfactorily why they use many-to-one on the User end when they have a 1->1 relationship b/w User and Address.


Maybe you should read the section again. Because it's a foreign key relationship, which is a bit different than the shared primary key value of the previous section. Why you should use that? Well, maybe because you have a legacy schema that already has it?

Quote:
Are you saying that when you have an optional 1->1 relationship you should always use a jointable?


Always? No. But whenever you want to avoid a NULLable column.

Quote:
Where's the example that shows nullable foreign keys and why isn't that approach preferable?


Because NULLs are evil. Read up on why ternary logic in SQL is bad, we have plenty of references to more literature in the book.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 1:32 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You are more than welcome to submit a patch that changes the binding in Hibernate XML for this case from many-to-one unique=true to a one-to-one.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 2:11 am 
Newbie

Joined: Tue Nov 25, 2003 11:49 pm
Posts: 12
Well the rationale for using many-to-one becomes confusing when you consider that it's one-to-one on the target end if you make the relationship bidirectional. So you have a 1-1 relationship yet each end is different.

What is it then that stops <one-to-one on the target end from behaving the same way the shared primary key approach works? Presumably when it sees property-ref if then knows it's the back pointer and not a shared primary key?

Consider how elegant the JPA annotations are.. it's just @OneToOne on either end.

I know this isn't going to change any time soon I'm just surprised because to me it's non-intuitive.

christian wrote:
Quote:
The authors don't explain satisfactorily why they use many-to-one on the User end when they have a 1->1 relationship b/w User and Address.


Maybe you should read the section again. Because it's a foreign key relationship, which is a bit different than the shared primary key value of the previous section. Why you should use that? Well, maybe because you have a legacy schema that already has it?

Quote:
Are you saying that when you have an optional 1->1 relationship you should always use a jointable?


Always? No. But whenever you want to avoid a NULLable column.

Quote:
Where's the example that shows nullable foreign keys and why isn't that approach preferable?


Because NULLs are evil. Read up on why ternary logic in SQL is bad, we have plenty of references to more literature in the book.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 4:21 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Because the binder for Hibernate XML mapping files doesn't support foreign keys on <one-to-one>. Please submit a patch.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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