public class User { private String account; private String password; private Set<Role> roleSet = new HashSet<Role>(); public String getAccount() { return account; } public void setAccount(String account) { this.account = account; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Set<Role> getRoleSet() { return roleSet; } public void setRoleSet(Set<Role> roleSet) { this.roleSet.addAll(roleSet); } } public class Role { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
这是两个实体类,两者是多对多的关系。User是存储在数据库中的,而Role则是从xml加载出来,我的问题是怎样才能把两者相结合。User跟Role的关联关系是由一张T_User_Role来描述的。
不同的数据源类型hibernate好像是没法这么映射的
如果两个实体都跑到一张表里边去,除了用自连接外,好像只有继承关系映射,所有的类张表!你参考下吧!