-->
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: Unidirectional OneToMany Best Practices
PostPosted: Fri Jan 13, 2006 7:50 pm 
Newbie

Joined: Fri Jan 13, 2006 7:31 pm
Posts: 3
Hibernate version: 3.1 + Annotations 3.1 beta 7

Mapping documents: @OneToMany @JoinTable vs. @JoinColumn

Code between sessionFactory.openSession() and session.close(): Using JBoss AS 4.0.3SP1 + EJB3RC3 Session Beans w/ entity manager

Name and version of the database you are using: PostgreSQL 8.1

Please forgive my data modeling ignorance. I need help understanding the reasoning of and strategies related to the unidirectional OneToMany best practices. In section 2.2.5.3.2.2 of the Hibernate Annotations 3.1 beta 7 Reference Guide(http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#d0e1146), the following is stated:

Quote:
A unidirectional one to many using a foreign key column in the owned entity is not that common and not really recommended. We strongly advise you to use a join table for this kind of association.


Can someone explain or point me to documentation that explains the reasoning behind this, the modeling and querying strategies related to this, and maybe give some scenarios that exemplify why the @JoinTable approach is strongly recommend and a scenario that demonstrates a good place to choose to use the @JoinColumn instead?

I've wondered about this and I ask for my own edification. In addition, a colleague who works against the same data as I do, but does not share the same middleware code, recently asked why I'm forcing him to do joins in situations where a select would suffice. He wasn't impressed with "because the Hibernate documentation recommends it" so I figure now's a pretty good time to fill in this hole in my own knowledge.

Thanks for the help!
Jonn


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 15, 2006 3:03 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
if you use JoinColumn, this means the FK is own by the targeted entity. In this case, it most certainly make sense to use a bidirectional association, since the associated entity (actuallyu table) is aware of the association.

_________________
Emmanuel


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