您好,欢迎来到好走旅游网。
搜索
您的当前位置:首页mybatis报错 Cause: java.sql.SQLException: 序列号无效

mybatis报错 Cause: java.sql.SQLException: 序列号无效

来源:好走旅游网

一、问题描述

 引入mybatis之后 在进行更新语句时候出现异常!!!

2024-08-12 15:35:26.670 [http-nio-8007-exec-1] DEBUG c.y.b.m.t.F.updateTaskAttrs -> debug,137 - ==>  Preparing: UPDATE ac_sl_flowelementattrs SET returnWay = ?, runWay = ?, jumpWay = ?, ccWay = ?, autoCCWay = ?, transfer = ?, countersign = ?, endTask = ?, refuse = ?, titleModel = ? WHERE ac_sl_flowelementattrs.tenant_id = 'test' AND task_def_key = ? 
2024-08-12 15:35:26.690 [http-nio-8007-exec-1] ERROR c.y.b.c.ProcessDefinitionController -> saveUserTaskProperties,160 - saveUserTaskProperties异常:nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='form_type', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #12 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: dm.jdbc.driver.DMException: 序列号无效 
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='form_type', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #12 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: dm.jdbc.driver.DMException: 序列号无效
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
	at com.sun.proxy.$Proxy148.update(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:288)
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:64)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
	at com.sun.proxy.$Proxy173.updateTaskAttrs(Unknown Source)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762)
	at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:64)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762)
	at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:57)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:58)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
Caused by: org.apache.ibatis.type.TypeException: Error setting null for parameter #12 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: dm.jdbc.driver.DMException: 序列号无效
	at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:67)
	at com.baomidou.mybatisplus.core.MybatisParameterHandler.setParameters(MybatisParameterHandler.java:234)
	... 153 common frames omitted
Caused by: dm.jdbc.driver.DMException: 序列号无效
	at dm.jdbc.driver.DBError.throwz(SourceFile:754)
	at dm.jdbc.driver.DmdbPreparedStatement.bindInParam(SourceFile:801)
	at dm.jdbc.driver.DmdbPreparedStatement.do_setNull(SourceFile:842)
	at dm.jdbc.driver.DmdbPreparedStatement.setNull(SourceFile:1809)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setNull(FilterChainImpl.java:3248)
	at com.alibaba.druid.filter.FilterAdapter.preparedStatement_setNull(FilterAdapter.java:1292)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setNull(FilterChainImpl.java:3245)
	at com.alibaba.druid.filter.FilterAdapter.preparedStatement_setNull(FilterAdapter.java:1292)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setNull(FilterChainImpl.java:3245)
	at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.setNull(PreparedStatementProxyImpl.java:529)
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.setNull(DruidPooledPreparedStatement.java:256)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:67)
	at com.sun.proxy.$Proxy255.setNull(Unknown Source)
	at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:65)
	... 154 common frames omitted


二、DEBUG问题位置并解决

走下面日志发现,错误在更新语句时候出现了sql语法错误org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property=‘form_type’, mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId=‘null’, jdbcTypeName=‘null’, expression=‘null’}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #12 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: dm.jdbc.driver.DMException: 序列号无效

其中关键文字:Could not set parameters for mapping 后面跟着了form_type字段名称,查看sql语句如下:

    <update id="***" parameterType="***">
        update **
        set returnWay=#{returnWay},
            ...此处省略
--             ,form_type=#{formType},
        where id = #{id}
    </update>

这里发现我们的sql中存在一行注释
-- ,form_type=#{formType}标识的代码,查阅mybatis官方文档说是会被预编译
因为包含了#
如果把-- ,form_type=#{formType}改成-- ,form_type={formType}也就是去掉#
就不会报错!!!

总结:在mybatis中,使用注释代码,不能包含mybatis标签的语法#{}或者${}都不可以
否则会预编译

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- haog.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务