@IdClass @IdClass 联合主键的 警告

来源:互联网 发布:html编辑器源码 编辑:程序博客网 时间:2024/04/27 19:14
 

运行下:结果杯具了: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 tocomposite 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.

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

0 0
原创粉丝点击