建立双向多对多关联关系
Project.java (项目表)
private Integer proid;
private String proname;
private Set<Employyee> employees = new HashSet<Employee>(0);
Employee.java (员工表)
private Integer empid;
private String empname;
private Set<Project> projects = new new HashSet<Employee>(0);
在Project.hbm.xml表中添加映射代码:<set name = "employees" table="PROEMP" cascade="save-update">
<key column="RPROID"></key>
<many-to-many class="cn.jbit.hibernatedemo.entity.Employee"
column="REMPID"/>
</set>
在Employee.hbm.xml表中添加映射代码:<set name = "projects" table="PROEMP" inverse="true">
<key column="REMPID"></key>
<many-to-many class="cn.jbit.hibernatedemo.entity.Project"
column="RPROID"/>
</set>
table:指定关系表的名称为PROEMP
cascade:表明保存或更新Project时,会联级保存或更新与他挂活力啊你的Employee对象
key子元素指定PROEMP的外键RPROID,用来参照PROJECT表
class:用来指定employees集合中存放的是employee对象,column指定PROEMP表的外键REMPID
用来参照EMOPLOYEE表