[英]Using LocalDateTime with @Version annotation in JPA
我的Entity
类中包含以下字段:
@Version
@Column(name = "updated")
private LocalDateTime lastUpdated;
@Column(name = "created")
private LocalDateTime created;
created
字段工作正常,因为我实现了从LocalDateTime
到Timestamp
的AttributeConverter
。
部署到容器时, lastUpdated
字段会出现以下错误:
java.lang.ClassCastException: org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter cannot be cast to org.hibernate.type.VersionType
我知道可以通过使用Timestamp
作为lastUpdated
的变量类型代替LocalDateTime
。
我想知道是否可以覆盖@Version
注释行为以接受LocalDateTime
作为变量类型。
尝试hibernate-java8
依赖关系,它支持Java 8特定的数据类型。
<!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-java8 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>5.1.0.Final</version>
</dependency>
下面来自休眠网站
支持使用Java8特定数据类型,例如域模型中的任何JSR 310日期/时间类型。
VersionType<Instant>
作为其中的一部分被添加,因此您可以根据需要使用它
更新1
已在H2 DB上具有hibernate-java8
依赖项的LocalDateTime
上检查了Version批注,它有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.