Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

ManyToMany & fields of association table

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic