4

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?

Ansgar Schulte
  • 463
  • 5
  • 15
  • FYI, similar Question: [LocalDate into database with JPA](http://stackoverflow.com/q/26254630/642706). But no good answers yet. Also, Thorben Janssen posted [How to persist LocalDate and LocalDateTime with JPA](http://www.thoughts-on-java.org/persist-localdate-localdatetime-jpa/). – Basil Bourque Feb 02 '16 at 21:58

1 Answers1

4

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

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
  • Thank you Neil. We will disucss that topic. For the moment we help ourselves by defining 31.12.9999 with semantic: Valid until the end of time ;-) – Ansgar Schulte Feb 03 '16 at 12:20