java - Spring Boot 3 和 Hibernate 6 迁移错误 : The conversion from datetime2 to DATETIMEOFFSET is unsupported

标签 java spring-boot hibernate hibernate-6.x

我将 Spring Boot 项目升级到 Spring Boot 3.0.0 和 Hibernate 6.x。应用程序启动时没有任何错误,当我访问任何具有 Instant 日期类型的表信息时,出现以下错误

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from datetime2 to DATETIMEOFFSET is unsupported.

我正在使用 SQL Server 2016 和 Spring Data 3.0.0

最佳答案

Hibernate 6 改变了即时日期类型的存储方式。

Instant now maps to the type code SqlType.TIMESTAMP_UTC by default, which maps to the SQL type timestamp with time zone if possible, and falls back to timestamp. Due to this change, schema validation errors could occur on some databases.

The migration to timestamp with time zone might require a migration expression like cast(old as timestamp with time zone). To retain backwards compatibility, configure the setting hibernate.type.preferred_instant_jdbc_type to TIMESTAMP.

Hibernate 5 以 2020-08-03 14:54:40.0000000 的格式存储 Java Instant,Hibernate 6 添加了时区,该时区将变为 2020- 08-03 14:54:40.0000000 +00:00

我不喜欢新的实现,但如果您想更改它,请将以下行添加到 Spring Boot 中的 application.properties 文件中

spring.jpa.properties.hibernate.type.preferred_instant_jdbc_type=TIMESTAMP

参见Hibernate 6 migration guide了解详情。

关于java - Spring Boot 3 和 Hibernate 6 迁移错误 : The conversion from datetime2 to DATETIMEOFFSET is unsupported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74609243/

相关文章:

java - 如何在没有持久性 xml 的情况下配置 hibernate 属性

java - libGDX Sprite 渲染失败

java - JDO (Google App Engine) 中的持久列表

java - 如何在 Java 中声明泛型方法

java - Angular : How to send file as part of form data that spring boot maps to the domain class?

java - 如何将数据传递到外键,在传递数据时我使用 postman 得到空值?

java - AmazonKinesisClient 构造函数已弃用

google-app-engine - 需要 "appengine.applications.get"权限

java - Maven 中的依赖问题

java - com.microsoft.sqlserver.jdbc.SQLServerException : Invalid column name 'xxx'