@IdClass @IdClass 联合主键的 警告

 

运行下:结果杯具了:20:55:57,078  WARN RootClass:215 - composite-id class does not override hashCode(): com.fendou.hibernate.SalDate

这句话告诉我们联合主键composite-id标签要求SalDate重写equals和hashCode方法.同时我们还需要实现Serializable接口。为什么要重写这两个方法以及实现Serializable

重写equals和hashCode方法是为了唯一确定一条记录以便用来作为持久化对象的标识。在Hibernate中要求一个标识必须是持久化的,所以必须将salDate实现Serializable接口。

帮助文档是这样说的:Unfortunately, this approach to composite identifiers means that a persistent object is its own identifier. There is no convenient "handle" other than the object itself. You must instantiate an instance of the persistent class itself and populate its identifier properties before you can load() the persistent state associated with a composite key.

上面那段英文中的后半部分是教我们怎么进行查询,在查询的时候我们先持久化一个主键对象标识然后查询:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值