| Author |
ManyToMany & fields of association table
|
Musab Al-Rawi
Ranch Hand
Joined: Aug 06, 2007
Posts: 231
|
|
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.
|
SCBCD - SCWCD - SCJD - SCJP - OCA
|
 |
Musab Al-Rawi
Ranch Hand
Joined: Aug 06, 2007
Posts: 231
|
|
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
Joined: May 17, 2006
Posts: 402
|
|
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
Joined: May 17, 2006
Posts: 402
|
|
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
Joined: Aug 06, 2007
Posts: 231
|
|
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
|
 |
 |
|
|
subject: ManyToMany & fields of association table
|
|
|