-->
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: Question about a comment in the docs
PostPosted: Thu Jan 11, 2007 7:45 pm 
Newbie

Joined: Thu Jan 11, 2007 7:38 pm
Posts: 4
Hello,

I'm new to Hibernate and working my way through the documentation.

In chapter seven its says a unidirectional 1..m relationship on a foreign key is not recommended and that a join table is the preferred way to go.

Why is that preferred? Poking the 'one's FK into the 'many' table seemed simple and straightforward, but unfortunately the authors don't explain their reasoning for preferring the join table. Are the authors recommending join tables for most relationships?

Thanks,
Greg


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 12, 2007 2:12 am 
Newbie

Joined: Tue Dec 19, 2006 11:05 am
Posts: 11
I think its because you can not navigate form the 'many-side' (Adress) to the 'one-side' (Person) of the association, but looking at the database structure you have a reference (forign key) from the 'one-side' to the many side. This is quite the other way round as the intended association...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 12, 2007 4:12 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Join tables for one-to-many associations are good for optional associations, e.g. if you have EMP and DEPT tables, you would need a nullable DEBT_ID column in the EMP table if there can be employees who are not assigned to a particular department. A separate EMP_DEPT table would avoid this nullable column (use Google to find out why SQL NULLs are evil), because you simply wouldn't have a record for this EMP in the join table, if it doesn't have a department.

_________________
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.  [ 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.