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

一、问题描述

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

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: 序列号无效

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标签的语法#{}或者${}都不可以
否则会预编译

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小码农吗

感谢您的大力支持,感谢感谢!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值