Mybatis Plus update time error: Could not set property ‘updateTime’

background     

Encountered this problem for several hours, almost driven crazy. Record it.

Let me talk about the environment, MySQL database, the field name in the table is update_time, and the type is datetime. The corresponding variable in the Java entity class is updateTime of type java.util.Date.

After the environment account is completed, when I use the update statement to update the record, I keep getting an error saying that the type does not match. Post the error message:

  1 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Could not set property 'updateTime' of 'class com.sinosoft.secloud.admin.api.entity.CtgAppInfo' with value '2019-11-07T10:12:39.257' Cause: java.lang.IllegalArgumentException: argument type mismatch
  2     at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
  3     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
  4     at com.sun.proxy.$Proxy187.update(Unknown Source)
  5     at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:294)
  6     at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:69)
  7     at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:61)
  8     at com.sun.proxy.$Proxy195.updateById(Unknown Source)
  9     at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.updateById(ServiceImpl.java:208)
 10     at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl$$FastClassBySpringCGLIB$$76535273.invoke(<generated>)
 11     at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
 12     at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684)
 13     at com.sinosoft.secloud.admin.service.impl.AppInfoServiceImpl$$EnhancerBySpringCGLIB$$2ee21674.updateById(<generated>)
 14     at com.sinosoft.secloud.admin.controller.AppInfoController.update(AppInfoController.java:96)
 15     at com.sinosoft.secloud.admin.controller.AppInfoController$$FastClassBySpringCGLIB$$4d69b343.invoke(<generated>)
 16     at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
 17     at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
 18     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
 19     at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
 20     at com.sinosoft.secloud.common.log.aspect.SysLogAspect.around(SysLogAspect.java:36)
 21     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 22     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 23     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 24     at java.lang.reflect.Method.invoke(Method.java:497)
 25     at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
 26     at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
 27     at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
 28     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
 29     at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
 30     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 31     at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
 32     at com.sinosoft.secloud.admin.controller.AppInfoController$$EnhancerBySpringCGLIB$$8e8549a.update(<generated>)
 33     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 34     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 35     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 36     at java.lang.reflect.Method.invoke(Method.java:497)
 37     at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
 38     at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
 39     at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
 40     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
 41     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
 42     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
 43     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
 44     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
 45     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
 46     at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:919)
 47     at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
 48     at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
 49     at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
 50     at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
 51     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
 52     at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90)
 53     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 54     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 55     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 56     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
 57     at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
 58     at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
 59     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 60     at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
 61     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 62     at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
 63     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 64     at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
 65     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 66     at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
 67     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 68     at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
 69     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 70     at org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter.doFilter(OAuth2AuthenticationProcessingFilter.java:176)
 71     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 72     at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
 73     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 74     at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)
 75     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 76     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 77     at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
 78     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 79     at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
 80     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 81     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 82     at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
 83     at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
 84     at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
 85     at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
 86     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 87     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 88     at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
 89     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 90     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 91     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 92     at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
 93     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 94     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 95     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 96     at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
 97     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 98     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 99     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
100     at org.springframework.cloud.sleuth.instrument.web.ExceptionLoggingFilter.doFilter(ExceptionLoggingFilter.java:50)
101     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
102     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
103     at brave.servlet.TracingFilter.doFilter(TracingFilter.java:86)
104     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
105     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
106     at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:117)
107     at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:106)
108     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
109     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
110     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
111     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
112     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
113     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
114     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
115     at com.sinosoft.secloud.common.data.tenant.TenantContextHolderFilter.doFilter(TenantContextHolderFilter.java:41)
116     at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
117     at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
118     at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
119     at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
120     at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
121     at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
122     at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
123     at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
124     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
125     at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
126     at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
127     at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
128     at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
129     at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
130     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
131     at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
132     at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
133     at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
134     at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
135     at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
136     at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
137     at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
138     at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
139     at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
140     at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
141     at io.undertow.server.Connectors.executeRootHandler(Connectors.java:364)
142     at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
143     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
144     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
145     at java.lang.Thread.run(Thread.java:745)
146 Caused by: org.apache.ibatis.reflection.ReflectionException: Could not set property 'updateTime' of 'class com.sinosoft.secloud.admin.api.entity.CtgAppInfo' with value '2019-11-07T10:12:39.257' Cause: java.lang.IllegalArgumentException: argument type mismatch
147     at org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:185)
148     at org.apache.ibatis.reflection.wrapper.BeanWrapper.set(BeanWrapper.java:59)
149     at org.apache.ibatis.reflection.MetaObject.setValue(MetaObject.java:140)
150     at com.baomidou.mybatisplus.core.handlers.MetaObjectHandler.setFieldValByName(MetaObjectHandler.java:72)
151     at com.sinosoft.secloud.common.data.mybatis.ModelMetaObjectHandler.updateFill(ModelMetaObjectHandler.java:54)
152     at com.baomidou.mybatisplus.core.MybatisDefaultParameterHandler.populateKeys(MybatisDefaultParameterHandler.java:192)
153     at com.baomidou.mybatisplus.core.MybatisDefaultParameterHandler.processBatch(MybatisDefaultParameterHandler.java:120)
154     at com.baomidou.mybatisplus.core.MybatisDefaultParameterHandler.<init>(MybatisDefaultParameterHandler.java:51)
155     at com.baomidou.mybatisplus.core.MybatisXMLLanguageDriver.createParameterHandler(MybatisXMLLanguageDriver.java:34)
156     at com.baomidou.mybatisplus.core.MybatisXMLLanguageDriver.createParameterHandler(MybatisXMLLanguageDriver.java:28)
157     at org.apache.ibatis.session.Configuration.newParameterHandler(Configuration.java:550)
158     at org.apache.ibatis.executor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:69)
159     at org.apache.ibatis.executor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:41)
160     at org.apache.ibatis.executor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:46)
161     at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:563)
162     at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
163     at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
164     at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
165     at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
166     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
167     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
168     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
169     at java.lang.reflect.Method.invoke(Method.java:497)
170     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
171     ... 142 common frames omitted
172 Caused by: java.lang.IllegalArgumentException: argument type mismatch
173     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
174     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
175     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
176     at java.lang.reflect.Method.invoke(Method.java:497)
177     at org.apache.ibatis.reflection.invoker.MethodInvoker.invoke(MethodInvoker.java:44)
178     at org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:180)
179     ... 165 common frames omitted

After repeated checks, there is nothing wrong with the types in the database and the Java entity classes, and the cache is also cleaned up, and they are all invalid. This has always been wrong. Then the time is not updated directly in the logic layer, only other fields are updated, the result is useless, and this error is still reported! So I suspected that there might be a problem with the Mybaits Plus framework. My colleague said that the update time might be automatically added, but I didn’t find a description on the official website for a long time. In the end, I figured out a solution by myself. The solution is attached below:


 

method one:

Modify the field name to something else, such as update_date or update_times

Method Two:

Keep the field name unchanged, change the field type in Java to java.time.LocalDateTime, and assign a value to LocalDateTime.now().

 

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *