-->
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: N:M:K Relation, N:M Relation with 3 tables
PostPosted: Mon Apr 14, 2008 2:55 pm 
Regular
Regular

Joined: Fri Feb 09, 2007 3:47 pm
Posts: 56
Hey,

here is my problem:

How can i make a n:m:k relation. The normal n:m relation have 2 tables, but i need 3 tables. Who can help me?

Greatz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 5:55 pm 
Newbie

Joined: Mon Apr 14, 2008 11:24 am
Posts: 5
I would be interested on the answer to your question. I am a newbie with Hibernate but I think I will need to model something similar in my next project.

I am assuming that you have something similar to the following:

Lets assume 3 entities: Person, Pet and House
and you want to model that a person can own multiple houses and a house can be owned by multiple persons, houses can host multiple pets and a pet can be taken care of at multiple houses. A person pets multiple pets and a pet is taken care of by multiple persons.

You would need a table T with the key of Person, Pet and House to keep track of the relationship.

I would probaly start trying to define this relationship by defining its own <class> and defining three one-to-many relationships from each entity to T.

Another approach would be to define 2 <set>s on each entity with the many-to-many relation to the third entity by means of the table T, but then I am not sure where would you put the attribute inverse="true" on each set. I guess it would depend of your application.


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