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来描述的。
问题补充:
To:zzzlyr
谢谢你的回复!
可能是我没有表述清楚我的问题,我的想法是,Role对象的属性值是存储在xml中,而我的User对象的属性值则是存储在数据库,两中对象的关系通过数据库中表T_User_Role来描述,我是想说能不能用Hibernate的方式来进行关联。