mybatis / mybatis-dynamic-sql

SQL DSL (Domain Specific Language) for Kotlin and Java. Supports rendering for MyBatis or Spring JDBC Templates
http://www.mybatis.org/mybatis-dynamic-sql/docs/introduction.html
Apache License 2.0
1.1k stars 213 forks source link

Error using operator in sql where condition #849

Closed hermer closed 1 month ago

hermer commented 1 month ago

Want to implement the following sql statement..

  select ... from ... WHERE  table1.qiezhangshu + table2.sunhaoshu > table1.zhibanLingliaoShuliang + table2.shiyongKucunshu 

where table1.qiezhangshu + table2.sunhaoshu) > #{parameters.p1} statement in DefaultSqlProviderImpl parameters.p1use org.mybatis.dynamic.sql.select.function.Add.of(firstTable.column(firstField.getDbColumn()), seconTable.column(seconField.getDbColumn()))

Upgrading from 1.3.0 to 1.5.2 Found problems before is OK The following exception

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='parameters.p1', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Cannot convert class org.mybatis.dynamic.sql.select.function.Add to SQL type requested due to com.mysql.cj.exceptions.WrongArgumentException - Invalid argument value: java.io.NotSerializableException
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
    at jdk.proxy2/jdk.proxy2.$Proxy211.selectList(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:166)
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:77)
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
    at jdk.proxy2/jdk.proxy2.$Proxy351.select(Unknown Source)
    at com.zerone.boot.framework.paas.orm.mapper.SqlMapperProxy.select(SqlMapperProxy.java:27)
    at org.apache.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:71)
    at org.apache.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:99)
    at org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke(DelegateProviderMetaDataInvoker.java:55)
    at org.apache.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)
    at org.apache.dubbo.rpc.filter.ClassLoaderCallbackFilter.invoke(ClassLoaderCallbackFilter.java:38)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at com.zerone.boot.framework.rpc.filter.ProviderContextTransferFilter.invoke(ProviderContextTransferFilter.java:39)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at org.apache.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:77)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at org.apache.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:46)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at com.zerone.boot.framework.rpc.filter.ProviderExceptionFilter.invoke(ProviderExceptionFilter.java:37)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:99)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at org.apache.dubbo.auth.filter.ProviderAuthFilter.invoke(ProviderAuthFilter.java:53)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at org.apache.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:131)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at org.apache.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:191)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at org.apache.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:54)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at org.apache.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:41)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at org.apache.dubbo.rpc.filter.ProfilerServerFilter.invoke(ProfilerServerFilter.java:56)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CopyOfFilterChainNode.invoke(FilterChainBuilder.java:321)
    at org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder$CallbackRegistrationInvoker.invoke(FilterChainBuilder.java:193)
    at org.apache.dubbo.rpc.protocol.tri.call.AbstractServerCallListener.invoke(AbstractServerCallListener.java:61)
    at org.apache.dubbo.rpc.protocol.tri.call.UnaryServerCallListener.onComplete(UnaryServerCallListener.java:55)
    at org.apache.dubbo.rpc.protocol.tri.call.AbstractServerCall.onComplete(AbstractServerCall.java:172)
    at org.apache.dubbo.rpc.protocol.tri.stream.TripleServerStream$ServerTransportObserver$ServerDecoderListener.close(TripleServerStream.java:440)
    at org.apache.dubbo.rpc.protocol.tri.frame.TriDecoder.deliver(TriDecoder.java:102)
    at org.apache.dubbo.rpc.protocol.tri.frame.TriDecoder.close(TriDecoder.java:68)
    at org.apache.dubbo.rpc.protocol.tri.stream.TripleServerStream$ServerTransportObserver.doOnData(TripleServerStream.java:410)
    at org.apache.dubbo.rpc.protocol.tri.stream.TripleServerStream$ServerTransportObserver.lambda$onData$1(TripleServerStream.java:401)
    at org.apache.dubbo.common.threadpool.serial.SerializingExecutor.run(SerializingExecutor.java:99)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at org.apache.dubbo.common.threadlocal.InternalRunnable.run(InternalRunnable.java:41)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='parameters.p1', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Cannot convert class org.mybatis.dynamic.sql.select.function.Add to SQL type requested due to com.mysql.cj.exceptions.WrongArgumentException - Invalid argument value: java.io.NotSerializableException
    at com.baomidou.mybatisplus.core.MybatisParameterHandler.setParameters(MybatisParameterHandler.java:238)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:94)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)
    at jdk.internal.reflect.GeneratedMethodAccessor114.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:64)
    at jdk.proxy2/jdk.proxy2.$Proxy216.parameterize(Unknown Source)
    at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:88)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
    at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:81)
    at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62)
    at jdk.proxy2/jdk.proxy2.$Proxy215.query(Unknown Source)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
    at jdk.internal.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427)
    ... 67 common frames omitted
Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Cannot convert class org.mybatis.dynamic.sql.select.function.Add to SQL type requested due to com.mysql.cj.exceptions.WrongArgumentException - Invalid argument value: java.io.NotSerializableException
    at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:75)
    at com.baomidou.mybatisplus.core.MybatisParameterHandler.setParameters(MybatisParameterHandler.java:236)
    ... 89 common frames omitted
Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Cannot convert class org.mybatis.dynamic.sql.select.function.Add to SQL type requested due to com.mysql.cj.exceptions.WrongArgumentException - Invalid argument value: java.io.NotSerializableException
    at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:75)
    at org.apache.ibatis.type.UnknownTypeHandler.setNonNullParameter(UnknownTypeHandler.java:67)
    at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:73)
    ... 90 common frames omitted
Caused by: java.sql.SQLException: Cannot convert class org.mybatis.dynamic.sql.select.function.Add to SQL type requested due to com.mysql.cj.exceptions.WrongArgumentException - Invalid argument value: java.io.NotSerializableException
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:130)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ClientPreparedStatement.setObject(ClientPreparedStatement.java:1634)
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setObject(FilterChainImpl.java:3454)
    at com.alibaba.druid.filter.FilterAdapter.preparedStatement_setObject(FilterAdapter.java:1304)
    at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setObject(FilterChainImpl.java:3451)
    at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.setObject(PreparedStatementProxyImpl.java:547)
    at com.alibaba.druid.pool.DruidPooledPreparedStatement.setObject(DruidPooledPreparedStatement.java:466)
    at jdk.internal.reflect.GeneratedMethodAccessor537.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:67)
    at jdk.proxy3/jdk.proxy3.$Proxy218.setObject(Unknown Source)
    at org.apache.ibatis.type.ObjectTypeHandler.setNonNullParameter(ObjectTypeHandler.java:31)
    at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:73)
    ... 92 common frames omitted
Caused by: com.mysql.cj.exceptions.WrongArgumentException: Invalid argument value: java.io.NotSerializableException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:62)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:150)
    at com.mysql.cj.NativeQueryBindings.setSerializableObject(NativeQueryBindings.java:552)
    at com.mysql.cj.NativeQueryBindings.setObject(NativeQueryBindings.java:509)
    at com.mysql.cj.NativeQueryBindings.setObject(NativeQueryBindings.java:480)
    at com.mysql.cj.jdbc.ClientPreparedStatement.setObject(ClientPreparedStatement.java:1632)
    ... 104 common frames omitted
Caused by: java.io.NotSerializableException: org.mybatis.dynamic.sql.select.function.Add
    at java.base/java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1197)
    at java.base/java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354)
    at com.mysql.cj.NativeQueryBindings.setSerializableObject(NativeQueryBindings.java:541)
    ... 107 common frames omitted
hermer commented 1 month ago

@jeffgbutler help

hermer commented 1 month ago

SqlBuilder.isGreaterThan((BasicColumn)value) Type changed to BasicColumn is Normal