Hibernate @Temporal for Java 8 java.time.Instant [英] Hibernate @Temporal for Java 8 java.time.Instant
本文介绍了Hibernate @Temporal for Java 8 java.time.Instant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Hibernate并尝试执行以下操作:
I use Hibernate and try to do the following:
@Temporal(TemporalType.DATE)
@Column(name = "BIRTHDAY")
private Instant birthday;
但有这个例外:
Caused by: org.hibernate.AnnotationException: @Temporal should only be set on a java.util.Date or java.util.Calendar property:
如我所知,我试图使用
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>${hibernate.ver}</version>
</dependency>
但有相同的例外。我应该做一些额外的步骤或如何解决这种情况吗?
but have the same exception. Should I do some additional steps or how to resolve such a case?
推荐答案
你不能使用 @时间
使用java 8时间,如果你想要日期与时间一起使用 LocalDateTime
,如果你只想使用日期 LocalDate
没有 @Temporal
anotation。
You can not use @Temporal
with java 8 time, if you want date with time use LocalDateTime
, if you want only date use LocalDate
without @Temporal
anotation.
看起来也是 http://www.thoughts-on-java.org/persist-localdate-localdatetime-jpa/
这篇关于Hibernate @Temporal for Java 8 java.time.Instant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文