We are using Spring Data JPA to access a Derby-DB. Temporal values are defined as java.time.LocalDate (java 8 time api). Spring Data now is shipped with a org.springframework.data.convert.Jsr310Converters.LocalDateToDateConverter to convert LocalDate to java.util.Date, since - far as I know - JPA specification does not support LocalDate so far.
We now have an issue when converting a LocalDate.MAX to Date, resulting in the following exception (stripped):
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
Anyone who also faced this issue and have a suggestion to overcome this issue?
解决方案
java.util.Date doesn't support dates that far into the future. See its javadoc :
Instant can store points on the time-line further in the future and further in the past than Date.
Consequently you would have to define your own JPA AttributeConverter and maybe store it as a String, or some other type