我在Hibernate User
和Permission
中有两个实体,我想创建一个users
表,其中包含所有用户数据。然后,我想要一个表permissions
,其中列出了用户的所有可用权限及其默认值。最后,我想要一个表user_permissions
,它将可用的权限映射到用户ID并为这些权限设置一个值。
这就是我实际设置的方式,但是我认为这行不通:
// User Entity
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue
private long id;
@Column(nullable = false)
private String username;
@Column(nullable = false)
private String email;
@Column(nullable = false)
private String password;
@Column(nullable = false)
private Date registrationDate;
@Column
private Date lastLoginDate;
@Column
private String activationKey;
@Column
private String recoveryKey;
@JoinTable
private List<Permission> permissions;
@Column(nullable = false)
private boolean disabled;
}
// Permission Entity
@Entity
public class Permission {
@Id
@GeneratedValue
private long id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private Permission.Type type;
@Column(nullable = false)
private String value;
/**
* @author Jonas
*
*/
public enum Type {
STRING,
NUMBER,
FLAG
}
}
谢谢您的帮助!