当前使用版本(必填,否则不予处理)
3.5.2
该问题是如何引起的?(确定最新版也有问题再提!!!)
使用多租户插件时,执行insert语句会出现一下类型转换异常 class net.sf.jsqlparser.statement.select.SetOperationList cannot be cast to class net.sf.jsqlparser.statement.select.PlainSelect (net.sf.jsqlparser.statement.select.SetOperationList and net.sf.jsqlparser.statement.select.PlainSelect
问题出在TenantLineInnerInterceptor中的一下方法的PlainSelect plainSelect = (PlainSelect)selectBody;行, protected void processInsertSelect(SelectBody selectBody) { PlainSelect plainSelect = (PlainSelect)selectBody; FromItem fromItem = plainSelect.getFromItem(); if (fromItem instanceof Table) { this.processPlainSelect(plainSelect); this.appendSelectItem(plainSelect.getSelectItems()); } else if (fromItem instanceof SubSelect) { SubSelect subSelect = (SubSelect)fromItem; this.appendSelectItem(plainSelect.getSelectItems()); this.processInsertSelect(subSelect.getSelectBody()); }
}
selectBody是SetOperationList 类型
重现步骤(如果有就写完整)
报错信息
Caused by: java.lang.ClassCastException: class net.sf.jsqlparser.statement.select.SetOperationList cannot be cast to class net.sf.jsqlparser.statement.select.PlainSelect (net.sf.jsqlparser.statement.select.SetOperationList and net.sf.jsqlparser.statement.select.PlainSelect are in unnamed module of loader 'app') at com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor.processInsertSelect(TenantLineInnerInterceptor.java:204) at com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor.processInsert(TenantLineInnerInterceptor.java:138) at com.baomidou.mybatisplus.extension.parser.JsqlParserSupport.processParser(JsqlParserSupport.java:89) at com.baomidou.mybatisplus.extension.parser.JsqlParserSupport.parserMulti(JsqlParserSupport.java:69) at com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor.beforePrepare(TenantLineInnerInterceptor.java:78) at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:102) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) at jdk.proxy2/jdk.proxy2.$Proxy146.prepare(Unknown Source) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:87) at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) 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.Invocation.proceed(Invocation.java:49) at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:106) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) at jdk.proxy2/jdk.proxy2.$Proxy145.update(Unknown Source) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) 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.$Proxy145.update(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:194)
Comment From: miemieYaho
可否提供一下你的sql
Comment From: ssnhqzj
INSERT INTO sys_dept (parent_id, dept_name, ancestors, order_num, leader, status, create_by, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, sysdate())
Comment From: ssnhqzj
可否提供一下你的sql
INSERT INTO sys_dept (parent_id, dept_name, ancestors, order_num, leader, status, create_by, create_time) VALUES (?, ?, ?, ?, ?, ?, ?, sysdate())
Comment From: miemieYaho
你的sql实测并不会抛异常
Comment From: ssnhqzj
你的sql实测并不会抛异常 我这边就是一个普通的插入语句,没什么特别之处呢 insert into sys_dept(
id, parent_id, dept_name, ancestors, order_num, leader, phone, email, status, create_by, create_time )values(#{id}, #{parentId}, #{deptName}, #{ancestors}, #{orderNum}, #{leader}, #{phone}, #{email}, #{status}, #{createBy}, sysdate() )
能不能把你测试demo发我一份呢,345412682@qq.com,感谢
Comment From: ssnhqzj
Comment From: miemieYaho
本项目TenantLineInnerInterceptorTest
Comment From: ssnhqzj
导致这个问题的原因是因为jsqlparser版本的引起的,项目中用到了PageHelper,PageHelper较新的版本依赖的是jsqlparser:4.5;改成项目中依赖的jsqlparser使用4.4就可以了
Comment From: pyf31415926
如何解决呀
Comment From: roostinghawk
如何解决呀
@pyf31415926 我的解决方法是回退到 JSqlParser 的 4.4 版本(或者说忽略 4.5),但要注意 4.4 有关键字问题,比如 “ur“ 别名