📄 18_复合主键映射(要实现序列化接口).txt
字号:
复合(联合)主键映射
通常将复合主键相关的属性,单独放到一个类中(所有主键单独一个类)
* 此类必须实现序列化接口
* 覆写hashcode和equals方法
PK implements Serializable
//实现接口实现序列化 覆写hashcode和equals方法
//这不是一个实体类不能通过session.save()方法保存
private int fiscalYear; //核算年
private int fiscalPeriod; //核算月
===============================================================
Putong // 普通类
private PK pk ; // 主键类的引用
private Date beginDate; // 开始日期
private Date endDate; // 结束日期
private String periodSts; // 状态
===============================================================
Putong.hbm.xml 唯一的一个映射文件
<hibernate-mapping package="com.tcit.hibernate">
<class name="Putong" table="t_PK">
<composite-id name="pk"> <!-- 因为现在有了两个主键所以就必须用到这个标签 -->
<key-property name="fiscalYear"/>
<key-property name="fiscalPeriod"/>
</composite-id>
<property name="beginDate"/>
<property name="endDate"/>
<property name="periodSts"/>
</class>
</hibernate-mapping>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -