-->
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: Why unidirectional one-to-many association not recommendated
PostPosted: Tue Jan 17, 2006 12:29 am 
Beginner
Beginner

Joined: Wed Oct 05, 2005 12:29 pm
Posts: 22
Hi,

Can someone tell me why a unidirectional one-to-many association on a foreign key is not recommendated?

It is stated so in the hibernated manual, chapter 8. It is also stated that a unidirectional one-to-many association on a join table is much preferred.

The recommended method approach requires maintaining an extra table, which is I find is counter intiutive.

Is there any writup this?

Many thanks in advance,

regards,
Yee


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 4:52 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
Hi,

Using unidirectional one-to-many (inverse=false) first saves the child (with null in foreign key column) and then updates it to create the association.
Using inverse=true NH does nothing even if one-to-many collection is dirty, so you need the other side of the association (many-to-one) to create the link, but the benefit is that the FK value is never null (especially if used with cascade=all-delete-orphan)

In my opinon instead of messy workarounds with link-table it is much better to use inverse=true.

_________________
michal


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 5:16 am 
Beginner
Beginner

Joined: Wed Oct 05, 2005 12:29 pm
Posts: 22
I see - hibernate manual is a bit misleading on this. The recommendation should really be that one should stick to bidirectional associations (inverse = true), rather than saying that using join table is much preferred.

Thanks.

Yee


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 5:31 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I believe the manual you read was for Hibernate 3, not for 2.1.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 5:39 am 
Beginner
Beginner

Joined: Wed Oct 05, 2005 12:29 pm
Posts: 22
Yes - it was downloaded on Oct 4, 2005 - hibernate Reference Documentation V3.0.5


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.