I’ve got the following situation:
- A User object has a Set of Permission objects (
Set<Permission>) - Each User can have zero or more Permissions
- A Permission object has three fields
- The three fields of Permission make up the composite
key for that permission. - As a consequence of this, we want exactly
one instance in the DB of each Permission. Each user can potentially
have the same Permission. - The User object therefore has a
many-to-many relationship with Permission.
The question is: how, in this situation, do I make the Permission entity a composite key of itself? I’m particularly interested in doing this in the context of this many-to-many relationship.
Any ideas?
1º A Permission object has three fields
2º The three fields of Permission up make up the composite key
Both property and compound primary keys share the same columns
So Your question looks like this one
But do not forget
And
But if you do not like the approach as shown above, you can do the following one
regards,