gpt4 book ai didi

spring - 使用 Spring Data : column $COLUMN_NAME is of type timestamp without time zone but expression is of type bytea 的 postgres 中的时间戳错误

转载 作者:行者123 更新时间:2023-11-29 11:29:11 30 4
gpt4 key购买 nike

使用以下内容:

甲骨文 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.

我可以为这个领域写一个转换器,但应该有一个标准的方法,我感觉我遗漏了一些东西,因为环顾四周,我发现非常接近实际工作的实现。

最佳答案

经过一些研究,我找到了 this page, Using Java 8 Date and Time classes来自官方 postgres 文档并将属性类型更改为 LocalDateTime 而不是 Instant:

Java
@Column(name = "meal_time", nullable = false)
private LocalDateTime mealTime = LocalDateTime.now();

这解决了问题,并且是该特定项目中可以接受的解决方案。

关于spring - 使用 Spring Data : column $COLUMN_NAME is of type timestamp without time zone but expression is of type bytea 的 postgres 中的时间戳错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51487251/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com