我将 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/