我们正在使用 Spring Data JPA 访问 Derby-DB。时间值定义为 java.time.LocalDate(java 8 时间 api)。 Spring Data 现在随附了 org.springframework.data.convert.Jsr310Converters.LocalDateToDateConverter 以将 LocalDate 转换为 java.util.Date,因为据我所知,JPA 规范目前不支持 LocalDate。
我们现在在将 LocalDate.MAX 转换为 Date 时遇到问题,导致以下异常(已删除):
Caused by: java.lang.IllegalArgumentException: java.lang.ArithmeticException: long overflow
at java.util.Date.from(Unknown Source)
at org.springframework.data.convert.Jsr310Converters$LocalDateToDateConverter.convert(Jsr310Converters.java:116)
at org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters$LocalDateConverter.convertToDatabaseColumn(Jsr310JpaConverters.java:52)
at org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters$LocalDateConverter.convertToDatabaseColumn(Jsr310JpaConverters.java:47)
at org.hibernate.type.descriptor.converter.AttributeConverterSqlTypeDescriptorAdapter$1.bind(AttributeConverterSqlTypeDescriptorAdapter.java:97)
... 79 more
Caused by: java.lang.ArithmeticException: long overflow
at java.lang.Math.multiplyExact(Unknown Source)
at java.time.Instant.toEpochMilli(Unknown Source)
... 84 more
有谁也遇到过这个问题并且有解决这个问题的建议吗?
最佳答案
java.util.Date
不支持遥远 future 的日期。查看其 javadoc :
Instant
can store points on the time-line further in the future and further in the past thanDate
.
因此,您必须定义自己的 JPA AttributeConverter
并将其存储为字符串或其他类型
关于java - 将 LocalDate.MAX 转换为日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35149884/