Skip to content

[错误报告]: 描述:使用unionAll时报class net.sf.jsqlparser.statement.select.ParenthesedSelect cannot be cast to class net.sf.jsqlparser.statement.select.PlainSelect #333

@journeywent

Description

@journeywent

确认

  • 我的版本是最新版本, 我的版本号与 version 相同, 并且项目里无依赖冲突
  • 我已经在 issue 中搜索过, 确认问题没有被提出过
  • 我已经修改标题, 将标题中的 描述 替换为遇到的问题

当前程序版本

1.5.4

问题描述

mybatis-plus版本3.5.14,mybatis-plus-join版本1.5.4。使用unionAll时报类型转换异常。
public Page getUserPageByName(Page page, String paramName) {
MPJLambdaWrapper wrapper = new MPJLambdaWrapper();
wrapper.selectAs(SysUser::getUserId, SmartSearchUserPageVO::getUserId)
.selectAs(SysUser::getUsername, SmartSearchUserPageVO::getUsername)
.selectAs(SysUser::getPhone, SmartSearchUserPageVO::getPhone)
.selectAs(SysUser::getNickname, SmartSearchUserPageVO::getNickname)
.selectAs(SysUser::getName, SmartSearchUserPageVO::getName)
.selectAs(SysUser::getType, SmartSearchUserPageVO::getType)
.selectAs("1", SmartSearchUserPageVO::getFavoriteStatus)
.unionAll(SysUser.class, w -> w.selectAs(SysUser::getUserId, SmartSearchUserPageVO::getUserId)
.selectAs(SysUser::getUsername, SmartSearchUserPageVO::getUsername)
.selectAs(SysUser::getPhone, SmartSearchUserPageVO::getPhone)
.selectAs(SysUser::getNickname, SmartSearchUserPageVO::getNickname)
.selectAs(SysUser::getName, SmartSearchUserPageVO::getName)
.selectAs(SysUser::getType, SmartSearchUserPageVO::getType)
.selectAs("0", SmartSearchUserPageVO::getFavoriteStatus));
return baseMapper.selectJoinPage(page, SmartSearchUserPageVO.class, wrapper);
}

详细堆栈日志

2025-12-26 16:38:03.330 ERROR 48160 --- [  XNIO-1 task-2] c.h.e.c.s.h.GlobalBizExceptionHandler    : 全局异常信息 ex=
### Error querying database.  Cause: java.lang.ClassCastException: class net.sf.jsqlparser.statement.select.ParenthesedSelect cannot be cast to class net.sf.jsqlparser.statement.select.PlainSelect (net.sf.jsqlparser.statement.select.ParenthesedSelect and net.sf.jsqlparser.statement.select.PlainSelect are in unnamed module of loader 'app')
### Cause: java.lang.ClassCastException: class net.sf.jsqlparser.statement.select.ParenthesedSelect cannot be cast to class net.sf.jsqlparser.statement.select.PlainSelect (net.sf.jsqlparser.statement.select.ParenthesedSelect and net.sf.jsqlparser.statement.select.PlainSelect are in unnamed module of loader 'app')

org.mybatis.spring.MyBatisSystemException: 
### Error querying database.  Cause: java.lang.ClassCastException: class net.sf.jsqlparser.statement.select.ParenthesedSelect cannot be cast to class net.sf.jsqlparser.statement.select.PlainSelect (net.sf.jsqlparser.statement.select.ParenthesedSelect and net.sf.jsqlparser.statement.select.PlainSelect are in unnamed module of loader 'app')
### Cause: java.lang.ClassCastException: class net.sf.jsqlparser.statement.select.ParenthesedSelect cannot be cast to class net.sf.jsqlparser.statement.select.PlainSelect (net.sf.jsqlparser.statement.select.ParenthesedSelect and net.sf.jsqlparser.statement.select.PlainSelect are in unnamed module of loader 'app')
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:101)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:347)
	at jdk.proxy2/jdk.proxy2.$Proxy186.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:194)
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForIPage(MybatisMapperMethod.java:119)
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:84)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:156)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:93)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions