• Mybatis Plus 更新时间 updateTime字段报错 Could not set property 'updateTime'


    背景     

    遇到这个问题折腾好几个小时,差点被逼疯。记录一下。

    先说下环境,MySQL数据库,表中字段名为update_time,类型为datetime。Java实体类中对应的变量是java.util.Date类型的updateTime。

    环境交代完毕,使用update语句更新记录的时候,一直报错,说类型不匹配。贴上报错信息:

      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

    反复检查,数据库中的类型和Java实体类中的类型都没有错,缓存也清理了,都无效,一直就这个错。然后直接在逻辑层不更新这个时间了,只更新其他字段,结果没用,依旧报这个错!于是怀疑可能Mybaits Plus框架有问题,同事说可能会自动添加更新时间,可我在官网找半天也没找到相关描述。最后还是自己琢磨出解决办法了。下面附上解决方法:


    方法一:

    修改字段名为其他的,比如改成update_date或update_times

    方法二:

    字段名保持不变,将Java中的字段类型改为java.time.LocalDateTime,赋值的话LocalDateTime.now()即可。

    原因猜测

    个人还是觉得Mybaits Plus插件内部存在一个更新时间字段,导致冲突了。但没有证实。哪位大佬知道还请告知下。

  • 相关阅读:
    利用IIS应用请求转发ARR实现IIS和tomcat整合共用80端口
    Application Request Route实现IIS Server Farms集群负载详解
    jQuery插件之ajaxFileUpload
    百度上传组件
    jQuery选择器总结 jQuery 的选择器可谓之强大无比,这里简单地总结一下常用的元素查找方法
    如何使 WebAPI 自动生成漂亮又实用在线API文档
    Swagger+AutoRest 生成web api客户端(.Net)
    小程序开发的40个技术窍门,纯干货!
    为你下一个项目准备的 50 个 Bootstrap 插件
    In-Memory:内存数据库
  • 原文地址:https://www.cnblogs.com/plumsq/p/11811121.html
Copyright © 2020-2023  润新知