2017-08-15 73 views
0

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

回答

0

解決方法不是解決方法。對於java.time.Instant,PostgreSQL列的類型應該是TIMESTAMP。這在數據庫創建中是一個錯誤。