• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ManyToMany & fields of association table

 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

given that you have tables A and B that have a Many-to-Many relationship implemented using table C, where Table C has some fields related to the relationship (for example start_date, due_date whatever).

How can you access fields of the association table.

I know that we need to use the ManyToMany with mappedBy and JoinColumn but in class A i will have a Set<B> and in B I will Set<A>, where does C come and how can I access those fields that are related to the association (such as start_date).

thanks in advance.
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an example to explain my questions:
let's say there is entity FOLDER that has a many to many relationship with GROUP. I could do the design as follows:

Where and How can I represent INFO?
Is the following a better design (of courseDUMMY entity won't be named DUMMY!)?
Personally I want to go for the first design but I don't know how to represent INFO field.
In that case I define Folder and Group entities as follows:
In Folder
folder

In Group


Again how to access INFO column located in folder_group table?

Your help is greatly appreciated.
[ October 28, 2008: Message edited by: Musab Al-Rawi ]
 
Chaminda Amarasinghe
Ranch Hand
Posts: 404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Apparently very common situation, I also thought when I was reading Many-Many relationships. But I couldn't find a way..





I will try again

Thanks
 
Chaminda Amarasinghe
Ranch Hand
Posts: 404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rawi,

where are you going to put start_date? class A or B? I think you cant put it in any one of them. that does not belong to A or B directly.

I think in this type of situation we need another relationship and entity class called C. We have to devide this m-m relation ship to two 1-m and m-1 relationships

In this example

+------+ +------------+ +-----+
|FOLDER|--------|FOLDER_GROUP|-------|GROUP|
+------+ 1 n +------------+ n 1+-----+
| | | | |
| | | | |
| | | | |
(F_ID) (G_ID)| (INFO) (G_ID)
|
(F_ID)

One Folder has Many Or FolderGroupInfor (or FOLDER_GROUP ) and Each FolderGroupInfor has a Group

On other side,

One Group has Many FolderGroupInforand A FolderGroupInfor has a Group



What about others thought ?

Thanks
Cham
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cham,

I thought about that, but if that's the only solution (I don't know if it is or not that's why I am asking Ranchers) then probably ManyToMany works association table consists of PK of Entity tables (in other words not complete solution).

Experienced People, input please
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic