繁体   English   中英

Hibernate-在PostgreSQL中使用java.time.Instant

[英]Hibernate - Using java.time.Instant with PostgreSQL

由于类型不匹配,我得到了SchemaManagementException Hibernate版本是5.2.8.Final。 hibernate.ddl-auto设置为validate

org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [end_date] in table [certificate]; found [date (Types#DATE)], but expecting [timestamp (Types#TIMESTAMP)]

列实体的类型为java.time.Instant ,而PostgreSQL列的类型为TIMESTAMPTZ

@Column(name = "end_date")
private Instant endDate;

对于java.time.Instant ,Hibernate类型是InstantType ,它映射到TIMESTAMP JDBC类型。 因此,我理解为什么错误会提示您正在等待Types#TIMESTAMP 我不明白的是,该错误表明它找到了Types#DATE

资料来源: https : //docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html

一种解决方法是将列定义设置为

@Column(name = "end_date", columnDefinition="DATE")
private Instant endDate;

但我真的不相信这是一个解决方案。 对我而言,即时是TIMESTAMP ,而不是DATE

解决方法不是解决方案。 对于java.time.Instant ,PostgreSQL列应为TIMESTAMP类型。 这是数据库创建中的一个错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM