-->
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.  [ 4 posts ] 
Author Message
 Post subject: unidirectional one to many not recommended?
PostPosted: Mon Sep 22, 2008 5:29 pm 
Beginner
Beginner

Joined: Wed Mar 19, 2008 12:10 am
Posts: 36
in the hibernate docs it says doing a unidirectional one to many association is not recommended, and that a join table should be used instead. why is this and how would it be implemented? thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2008 6:15 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
"Unidirectional one to many" is a type of association.
The Hibernate team does not advise against using this type of association.
What you probably read, it that the Hibernate team advises against implementing this kind of association using just 2 tables, with one pointing to the other through a foreign key.

Instead, they probably advised using a third, "relation" table.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject: How do I do this?
PostPosted: Fri Oct 10, 2008 11:13 pm 
Newbie

Joined: Fri Oct 10, 2008 11:04 pm
Posts: 6
Location: California
Can anybody point me to some sample code that shows how to do this? The description I read in "Java Persistence with Hibernate" was very sketchy, and didn't help me set up the third table.

Also, can anybody explain why I should need a third table to do this? It seems to me all the needed information is in the two tables. My "One" table has IDs for all the entries, and my "Many" table has the ID for each row in the "One" table that owns it.


Top
 Profile  
 
 Post subject: Re: unidirectional one to many not recommended?
PostPosted: Fri Dec 18, 2009 10:39 pm 
Beginner
Beginner

Joined: Wed Mar 19, 2008 12:10 am
Posts: 36
if i do a bidirectional one to many association, then is it okay to not use a join table?

for example i'm doing:

class Owner {
@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, mappedBy="owner")
getCars()

and then on the many side i have:
Class Car {
getUser()
@ManyToOne
@JoinColumn(name="userId")


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