IllegalArgumentException:无法将java.time.LocalDateTime字段设置为java.sql.Timestamp [英] IllegalArgumentException: Can not set java.time.LocalDateTime field to java.sql.Timestamp

查看:712
本文介绍了IllegalArgumentException:无法将java.time.LocalDateTime字段设置为java.sql.Timestamp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做自我教学的测试任务.我的堆栈是Spring Boot/H2 date base/Hibernate

我喜欢REST完整的服务(实际上不是,现在我正在尝试对其进行修复)

有人告诉我,我有很多错误的代码决定和错误,因此我决定修复它.工作项目的初始状态在那里- https://github.com/iliapastushenko/testtaskREST

我已经开始重构它,而我所做的第一件事-摆脱了jackson-datatype-jsr310,因为它实际上对我来说是多余的事情-我已将其从POM和ClientappApplication类中删除,并编辑了我的Application类字段"dateCreated":

  @DateTimeFormat(pattern ="dd-MM-yyyy hh:mm:ss")@Type(type ="timestamp")私有LocalDateTime dateCreated; 

因此,当我尝试通过前端获取所需客户端的一个应用程序时我得到这种类型的异常:

  java.lang.IllegalArgumentException:无法设置java.time.LocalDateTime字段root.Model.Application.dateCreated为java.sql.Timestamp 

能否请您给我一个提示-怎么了?

解决方案

通过属性修复:

 < hibernate.version> 5.2.12.Final</hibernate.version> 

因此,由于Hibernate 5.2的所有功能都可以通过LocalDateTime正常运行,而不是像我之前所说的Hibernate 5.0.

I am doing test task for a self-teaching. My stack is Spring Boot/H2 date base/Hibernate

I have like a REST-full service (actually it is not, now I am trying to fix it)

I've been told that I have a lot of bad code decisions and mistakes, so I've decide to fix it. Initial state of a working project is there - https://github.com/iliapastushenko/testtaskREST

I've started to refactor that and first thing that I've made - got rid of jackson-datatype-jsr310 because it is actually redundant thing for me - I've deleted it from POM and ClientappApplication class and edited my Application class field "dateCreated":

@DateTimeFormat(pattern = "dd-MM-yyyy hh:mm:ss")
@Type(type="timestamp")
private LocalDateTime dateCreated;

So, when I am trying to get one application of needed client via frontend I get this type of Exception:

java.lang.IllegalArgumentException: Can not set java.time.LocalDateTime 
field root.Model.Application.dateCreated to java.sql.Timestamp

Could you please give me a hint - what is wrong ?

解决方案

Fixed it by property:

<hibernate.version>5.2.12.Final</hibernate.version>

So, since Hibernate 5.2 everything is okay with LocalDateTime, not Hibernate 5.0 as I was told earlier.

这篇关于IllegalArgumentException:无法将java.time.LocalDateTime字段设置为java.sql.Timestamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆