-->
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: one-to-mane VS join table
PostPosted: Wed Aug 27, 2008 11:23 am 
Newbie

Joined: Mon Oct 15, 2007 3:02 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

HI all.
Please explaine difference betwet this one-to-mane VS join table.
What advantage has first or second approach?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 12:18 pm 
Newbie

Joined: Fri Jan 25, 2008 6:17 pm
Posts: 2
Location: Pune, MH, India
join is used when two tables share the same primary key.

_________________
Kunal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 2:51 pm 
Newbie

Joined: Thu May 31, 2007 3:27 am
Posts: 11
join table between two tables using a primary key is a one-to-one relation (each row in table A have one and only one row with the same id in table B ).

So what is your question exactly? One-to-Many is a relation than can be achieved using a separate table, that is a join table, that keeps all references to the children for a given parent id. This approach often requires that the parent Object load the whole collection before attempting to modify it.

Another approach is to not use join table, and simply add an extra column, a foreign key, in the child table referering to the parent. So, in this case the relation is in fact managed by the child (instead of the parent as in the first approach). All the children of a Parent X is then translated to a query like this "returns all children that has the parent x".

Hibernate allows you to map a collection using one of these two methods. The first method must be used when the child does not know its parent, and the second method, when the child knows is parent, that is when the child has such method "child.getParent()".


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.