In my application, I have two classes: Activity and User. The relationship among them are:
- An activity can have multiple user. I have a field
List<User>for this purpose inActivityclass. - An user can belongs to multiple activities and in each activity he/she can have a specific role. I have refined a
Map<String, String>inUser, where thekeyof thisMapis theactivityIdand the value isroleId. I don’t have anyRoletable, as there are only four predefined Roles.
I am unable to understand should there be any ManyToOne or OneToMany or ManyToMany relationship between User and Activity. Or should I simple store the whole List<User> object along with Activity and Map<String, String> with User in database. If so, how can I store a whole List and a Map.
Any pointer would be very helpful for me.
I would first think about how the design would be in database. If I understand correctly, you would have 3 tables:
where Participation would have a foreign key to a user, a foreign key to an activity, and a role.
So I would map that simply as
And of course you can make these two associations bidirectional.