Reputation: 29806
In my application, I have two classes: Activity
and User
. The relationship among them are:
List<User>
for this purpose in Activity
class.Map<String, String>
in User
, where the key
of this Map
is the activityId
and the value is roleId
. I don't have any Role
table, 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.
Upvotes: 0
Views: 141
Reputation: 1504
User <-> Activity
is many to many
. Navigability can be bidirectional
- choice is yours.
You also need a UserActivityMap
object with three attributes (userId,ActivityId, roleId). RoleId can be an enum or an id of a RoleObject. In case of latter, you can define a lookup table and map RoleObject to that.
Upvotes: 1
Reputation: 691715
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.
Upvotes: 1