File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes ManyToMany & fields of association table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "ManyToMany & fields of association table" Watch "ManyToMany & fields of association table" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ManyToMany & fields of association table
 
Similar Threads
ManyToMany & fields of association table
updating association table
Ternary Association
Need help for Many to Many association
Hibernate - Annotations - many to many association