-->
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: Is it recommended to use @ManyToMany?
PostPosted: Fri May 16, 2008 2:39 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi,

In my RDBMS, I have table A, B & C.

A has many B and C has many B. It's a many to many relationship with a intermediate table B storing only the primary key of both A and C.

So, when defining my entity classes, should I just define A & C only with @ManyToMany annotations
OR
should I define entity class A, B & C and annotated using @OneToMany from A to B and C to B, then define a @ManyToOne from B to A and B to C.

Please advise.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 6:08 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
yes you could use the @ManyToMany annotation;
The possible drawbacks are 2:
1)As a design point of you, there is no more an entity representing B.
2)If later on you would need to add more data to B you will have to create the intermediate entity B.

The positive side is of course that if "B" is not an entity but you just used it as intermediate table, hiding it from the code you get much cleaner java classes; also it's easy to implement.

So it all depends if B represents something to you, other than a mere relationship.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 6:25 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Noted on your advice. I think I'll keep an entity to represent B.

_________________
Thank you.

Regards,
Jap.


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.