升级MySql V8.0.23后异常,V8.0.22及以下正常

1.异常:

 java.lang.ClassCastException: class java.time.LocalDateTime cannot be cast to class java.util.Date (java.time.LocalDateTime and java.util.Date are in module java.base of loader 'bootstrap')
at com.xxx.model.base.BaseSlOrder.getTransTime(BaseSlOrder.java:804)
at com.xxx.service.impl.SlOrderServiceImpl.getAssignableOrders(SlOrderServiceImpl.java:871)
at com.xxx.service.impl.SlOrderServiceImpl$$EnhancerByCGLIB$$271a0743.CGLIB$getAssignableOrders$40()
at com.xxx.service.impl.SlOrderServiceImpl$$EnhancerByCGLIB$$271a0743$$FastClassByCGLIB$$dcf070a4.invoke()
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at io.jboot.aop.cglib.JbootCglibCallback.lambda$intercept$0(JbootCglibCallback.java:64)
at com.jfinal.aop.Invocation.invoke(Invocation.java:101)
at io.jboot.aop.cglib.JbootCglibCallback.intercept(JbootCglibCallback.java:66)
at com.abitware.service.impl.SlOrderServiceImpl$$EnhancerByCGLIB$$271a0743.getAssignableOrders()
at com.abitware.controller.manage.ManageOrderController.alloc(ManageOrderController.java:269)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)


2.数据库字段类型:

`trans_time` datetime DEFAULT NULL COMMENT '交易发生时间',


3.生成的Model:

	public java.util.Date getTransTime() {
		return get("trans_time");
	}
	
	public M setTransTime(java.util.Date transTime) {
		set("trans_time", transTime);
		return (M)this;
	}


4.引用的MySql版本:

		<dependency>
		    <groupId>mysql</groupId>
		    <artifactId>mysql-connector-java</artifactId>
		    <version>8.0.23</version>
		</dependency>



评论区

JFinal

2021-01-19 15:48

异常信息不全,看不到是哪个方法调用的时候出现的,注意贴代码的时候先点击编辑器左上角的代码按钮,再复制代码

doubuxingle

2021-01-19 16:13

看样子像是8.0.23对于日期类型使用了LocalDateTime, 你尝试把setTransTime(java.util.Date transTime) 替换成setTransTime(java.util.LocalDateTime transTime)试试

prelove

2021-01-19 16:37

@doubuxingle 是的,用了java.time.LocalDateTime

prelove

2021-01-19 17:30

@JFinal @JFinal java.lang.ClassCastException: class java.time.LocalDateTime cannot be cast to class java.util.Date (java.time.LocalDateTime and java.util.Date are in module java.base of loader 'bootstrap')
at com.xxx.model.base.BaseSlOrder.getTransTime(BaseSlOrder.java:804)
at com.xxx.service.impl.SlOrderServiceImpl.getAssignableOrders(SlOrderServiceImpl.java:871)
at com.xxx.service.impl.SlOrderServiceImpl$$EnhancerByCGLIB$$271a0743.CGLIB$getAssignableOrders$40()
at com.xxx.service.impl.SlOrderServiceImpl$$EnhancerByCGLIB$$271a0743$$FastClassByCGLIB$$dcf070a4.invoke()
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at io.jboot.aop.cglib.JbootCglibCallback.lambda$intercept$0(JbootCglibCallback.java:64)
at com.jfinal.aop.Invocation.invoke(Invocation.java:101)
at io.jboot.aop.cglib.JbootCglibCallback.intercept(JbootCglibCallback.java:66)
at com.abitware.service.impl.SlOrderServiceImpl$$EnhancerByCGLIB$$271a0743.getAssignableOrders()
at com.abitware.controller.manage.ManageOrderController.alloc(ManageOrderController.java:269)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)

zzutligang

2021-01-19 18:39

这应该是jdbc驱动的问题吧。把date类型字段映射成java.time.LocalDateTime了,但生成的Model使用的是java.util.Date

JFinal

2021-01-19 22:34

@prelove class java.time.LocalDateTime 不能转化为 java.util.Date,单步调试看是哪行代码抛出的

然后贴出代码来,改进一下就可以了

fmpoffice

2021-04-26 11:53

@prelove 请问,具体的解决办法是啥?

SuperEric

2021-06-25 16:19

mysql-connector-java 8.0.22==>8.0.23+版本后,会出现这问题

SuperEric

2021-06-25 16:20

解决办法估计得重新生成model

热门反馈

扫码入社