org.hibernate.query.SemanticException:赋值表达式类型 sql.Timestamp 与赋值路径类型 OffsetDateTime 不匹配

问题描述 投票:0回答:1

我使用 Spring Boot 2.x 版本进行了以下 Postgres 查询,

UPDATE TABLE SET lastDateTime = CURRENT_TIMESTAMP WHERE x = :y

使用 h2 数据运行集成测试用例时,liquibase 配置有以下详细信息

databaseChangeLog:
  - changeSet:
      id: 10
      author: auth01
      changes:
        - createTable:
            tableName: TABLE
            columns:
              - column:
                  name: last_date_Time
                  type: TIMESTAMP WITH TIME ZONE

当升级到 Spring boot 3.x 时,如下所示

SPRING BOOT PARENT VERSION 3.1.3
hibernate-core-6.2.7.Final
org.postgresql:postgres:42.5.4
com.h2database:h2 : 2.2.224
io.hypersistence:hypersistence-utils-hibernate-62:3.5.3

错误是 org.hibernate.query.SemanticException: 赋值 表达式类型 [java.sql.Timestamp] 与赋值路径不匹配 类型 [java. time.OffsetDateTime] 路径 [alias_1617001542.lastDateTime]

我尝试将 TIMESTAMP WITH TIME ZONE 更改为 TIMESTAMP 和 DATETIME 并到 liquibase 中的 TIMESTAMPZ,但仍然没有运气。任何建议都是 赞赏

.

postgresql spring-boot hibernate h2 liquibase
1个回答
0
投票

Spring-Boot 3 使用 Hibernate 6 .

有一个迁移指南可从 Hibernate 5 迁移到 6。

即时映射更改

Instant 现在默认映射到类型代码 SqlType.TIMESTAMP_UTC, 如果可能的话,它映射到带有时区的 SQL 类型时间戳,以及 回退到时间戳。由于此更改,架构验证错误 可能会发生在某些数据库上。

迁移到带有时区的时间戳可能需要迁移 像cast这样的表达式(旧为带时区的时间戳)。

要保留向后兼容性,请配置设置 hibernate.type.preferred_instant_jdbc_type 为 TIMESTAMP。

尝试设置属性

hibernate.type.preferred_instant_jdbc_type=TIMESTAMP

© www.soinside.com 2019 - 2024. All rights reserved.