【发布时间】:2018-12-31 09:43:08
【问题描述】:
使用以下内容:
Oracle JDK 1.8.0._171
Spring boot 1.5.9-RELEASE
PostgreSQL 9.6
Postgres 驱动程序:42.2.4
从以下定义中得到错误:
表格栏:
sql
meal_time TIMESTAMP DEFAULT now() NOT NULL
实体属性定义:
java
@Column(name = "meal_time", nullable=false)
private Instant mealTime = Instant.now();
每当我尝试刷新或查询实体时都会抛出错误:
Caused by: org.postgresql.util.PSQLException: ERROR: column "meal_time" is of type timestamp without time zone but expression is of type bytea
Hint: You will need to rewrite or cast the expression.
我可以为这个领域编写一个转换器,但应该有一个标准的方式,感觉就像我在寻找一些我发现非常接近的实际工作的实现的例子时遗漏了一些东西。
【问题讨论】:
-
您是否尝试过在您的依赖项中包含
hibernate-java-8?spring-boot-starter-data-jpa:1.5.9依赖于hibernate-core:5.0.12,它不包括对 Java 8 的日期和时间 API 类型 AFAIK 的支持(不过,我认为它包含在hibernate-core中,适用于较新的 Hibernate 版本) -
@crizzis - 感谢您的反馈。只是按照您的建议尝试,但不幸的是同样的错误仍然存在。我现在将编写一个转换器,但仍在寻找更好的标准解决方案。
-
您在哪里告诉您的 JPA 提供者将
Instant保留为 TIMESTAMP?你还没有
标签: spring postgresql hibernate spring-boot jpa