A user table mapping to a typesafe enum, a user can has more than one roles, and of course one role can assigned to more than one users.
for example:
the user table has 2 fields (login_id, pwd), so the hibernate class is like:
Code:
public class user{
private String loginId;
private String pwd;
private Set roles = new HashSet();
}
the typesafe enum of the roles is like:
Code:
public class UserRole {
private final String roleName;
private UserRole(String roleName) {
this.roleName = roleName;
}
public String toString() {
return roleName;
}
public static final UserRole ROLE1 = new UserRole("role1");
public static final UserRole ROLE2 = new UserRole("role2");
public static final UserRole ROLE3 = new UserRole("role3");
}
and there's another table to save the relationships between the user and role, this table has 2 fields:(login_id, role_name);
so, how many classes I should write ? how many hbm.xml files I should write and how to write the hbm.xml files?
Thanks.