First, my classes:
Permissions, like "Delete Users", "Modify Files"
Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
class Permission {
@Id
@Column(name = "permission_id")
private Integer id;
private String key;
}
An interface permissions, like "User Adminstration"
Code:
@Entity
@PrimaryKeyJoinColumn(name="permission_id")
class InterfacePermission extends Permission {
private Integer type;
}
A role, like "Administrator", "Normal User"
Code:
@Entity
class Role {
@Id
@Column(name = "role_id")
private Integer id;
@ManyToMany(fetch = FetchType.LAZY,cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinTable(name = "role_permissions",
joinColumns = @JoinColumn(name ="role_id"),
inverseJoinColumns = @JoinColumn(name = "permission_id"))
private List<Permission> permissions;
}
And finally an user, like you and me...
Code:
@Entity
class User {
@Id
@Column(name = "user_id")
private Integer id;
@ManyToMany(fetch = FetchType.LAZY,cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinTable(name = "user_role",
joinColumns = @JoinColumn(name ="user_id"),
inverseJoinColumns = @JoinColumn(name = "role_id"))
private List<Role> roles;
@ManyToMany(fetch = FetchType.LAZY,cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinTable(name = "user_permissions",
joinColumns = @JoinColumn(name ="user_id"),
inverseJoinColumns = @JoinColumn(name = "permission_id"))
private List<Permission> permissions;
}
What I want in criteria is to retrieve all the interface permissions of an user.. so that would be the union of his particular permissions and permissions from his roles.
Oh, and I want my criteria to retrieve an InterfacePermission.class. I tried many things, but couldn't find for example, if a permission is in user roles, and how I can join the role with the permssions in that context.
Any help would be appreciated.
[/code]