Result表中 TestID 与 StudentID构成联合主键 则在Result.hbm.xml中映射关系如下:
<hibernate-mapping>
<class name="com.sanqing.po.Result" table="tb_result"><!-- 每个class对应一个持久化对象 -->
<composite-id ><!-- id元素用来定义主键标识,并指定主键生成策略 -->
<key-property name="testID" type="int"></key-property>
<key-property name="studentID" type="int"></key-property>
</composite-id>
<property name="result"></property><!-- 映射password属性 -->
</class>
</hibernate-mapping>
之后可能会报Serializable的错误,则在对应的类中实现Serializable接口,并添加如下代码即可。
import java.io.Serializable;
public class Result implements Serializable{
private static final long serialVersionUID = 1L;
......
private int testID;
private int studentID;
private int result;
.......
}