js localdate上一个月_转换LocalDate.MAX为日期

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值