想测试一下两个表数据的保存,其中表Employee引用了Department表的主键作为外键
Department的hbm文件:
<class name= "com.sunny.vo.Department " table= "department " schema= "dbo " catalog= "test ">
<id name= "id " type= "java.lang.Integer ">
<column name= "id " />
<generator class= "identity "> </generator>
</id>
<property name= "dname " type= "java.lang.String ">
<column name= "dname " length= "10 " />
</property>
<set name= "employees " inverse= "true ">
<key>
<column name= "pid " not-null= "true " />
</key>
<one-to-many class= "com.sunny.vo.Employee " />
</set>
</class>
Employee的hbm文件:
<hibernate-mapping>
<class name= "com.sunny.vo.Employee " table= "employee " schema= "dbo " catalog= "test ">
<id name= "id " type= "java.lang.Integer ">
<column name= "id " />
<generator class= "identity " />
</id>
<many-to-one name= "department " class= "com.sunny.vo.Department " fetch= "select ">
<column name= "pid " not-null= "true " />
</many-to-one>
<property name= "name " type= "java.lang.String ">
<column name= "name " length= "10 " />
</property>
</class>