At first I thought this solution could solve my problem:
@Entity
public class User {
@JoinTable(name = "user_permission",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "permission_id"))
@MapKeyJoinColumn(name = "project_id")
@ElementCollection
private Map<Project, Permission> permissions = new HashMap<>();
}
@Entity
public class Project {
...
}
@Entity
public class Permission {
...
}
But in this implementation, only one can be Permissionset to Project. I would like to fulfill the possibility of setting multiple permissions for a project so that the following can be true:
| user_id | project_id | permission_id |
|---------|------------|---------------|
| 1 | 1 | 1 |
|---------|------------|---------------|
| 1 | 1 | 2 |
|---------|------------|---------------|
| 1 | 2 | 1 |
|---------|------------|---------------|
| 1 | 2 | 2 |
|---------|------------|---------------|
| 2 | 1 | 1 |
|---------|------------|---------------|
| 2 | 1 | 2 |
|---------|------------|---------------|
| 2 | 2 | 1 |
|---------|------------|---------------|
| 2 | 2 | 2 |
source
share