-->
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: manytomany with 3 tables, how to do in Annotations?
PostPosted: Tue Nov 18, 2008 5:28 am 
Newbie

Joined: Tue Nov 18, 2008 5:01 am
Posts: 11
hi all

i have 3 tables and want to get them in relationship within one table:

following structure describes my problem:


Code:
table vehicle
-------------- 
v_id | name
--------------
1     | car
2     | boat



Code:
table part
--------------
p_id | name
--------------
1     | door
2     | seats
3     | buttons 



Code:
table color
--------------
c_id | color
--------------
1     | green
2     | blue
3     | red




Each vehicle could have several (vehicle)parts with different colors. so i want to get them in a manytomany relationship like:


Code:
table group
---------------------
v_id | p_id | c_id
---------------------
  1   |   1   |  1
  1   |   2   |  1
  1   |   3   |  2



i know how to get 2 Tables (Beans) in a manytomany relationship.

Bean vehicle:
----------

Code:
   @ManyToMany
   @JoinTable(
         name = "groupTable",
         joinColumns = {@JoinColumn(name = "v_id")},
         inverseJoinColumns = {@JoinColumn(name = "p_id")}
   )
   private Set<Part> p= new HashSet<Part>();


Bean part:
-----------

Code:
@ManyToMany(mappedBy = "part")
   private Set<Vehicle> v= new HashSet<Vehicle>();


But how could i get 3 tables (also Bean color) in a manytomany relationship?


All help would be great appreciated.

thank you in advance!!

maxpade


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 6:10 am 
Newbie

Joined: Tue Nov 18, 2008 5:01 am
Posts: 11
Hi there,

i suppose that manytomany relations in Hibernate supports primarily two tables. i think that i have to define a third table (vehiclePartColor-Bean) with 3 onetomany relations to solve that issue.

if there is another solution, than please post your reply.

thnaks

maxpade


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.