由於類型不匹配,我得到SchemaManagementException
。 Hibernate版本是5.2.8.Final。該hibernate.ddl-auto
設置爲validate
Hibernate - 在PostgreSQL中使用java.time.Instant
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
。