I started to create 2 classes for my 2 entities :
The relation between these 2 entities should be bidirectional.
JPA will then create a new relation entity named User-Group. In this table/entity we will find the User PK and the Group PK together.
My problem is : each User in a Group should have a "role". Default role is "member", but a User can also be "leader".
The "role" property doesn't exist in any of my classes and should be associated with the couple "User PK / Group PK" of the User-Group relation table created by JPA.
How can I handle the "role" property as it is not a User property neither a Group property but a User-Group property ? How to add this column in the User-Group table which is a JPA creation ?
Thanx for your help.
The easiest way is to split the Many-to-Many in two One-To-Many relationships towards a new entity : you create a UserRoleInAGroup class containing the role field, a group and a user.
The 2 resulting One-To-Many relationships are :
I hope it helps.