Exception | ShardingSphere | ShardingSphere引发的IndexOutOfBoundsException
创始人
2024-03-08 01:28:09
0

ShardingSphere引发的IndexOutOfBoundsException

  • 一、异常
  • 二、 原因
  • 三、解决方法
  • 四、总结

一、异常

在这里插入图片描述

### Error querying database.  Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
### The error may exist in file [D:\JetBrains\Idea\workspace\zohe\bjxz\ruoyi-system\target\classes\mapper\business\device\AlertInfoMapper.xml]
### The error may involve com.zhuohe.business.mapper.AlertInfoMapper.selectAlertInfoList_COUNT
### The error occurred while handling results
### SQL: SELECT count(0) FROM alert_info a LEFT JOIN scene b ON a.scene_id = b.scene_id WHERE a.alert_type = ?
### Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)... 124 common frames omitted
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0at java.util.ArrayList.rangeCheck(ArrayList.java:653)at java.util.ArrayList.get(ArrayList.java:429)at org.apache.shardingsphere.core.merge.dql.DQLMergeEngine.(DQLMergeEngine.java:71)at org.apache.shardingsphere.core.merge.MergeEngineFactory.newInstance(MergeEngineFactory.java:58)at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.getResultSet(ShardingPreparedStatement.java:139)at sun.reflect.GeneratedMethodAccessor96.invoke(Unknown Source)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:69)at com.sun.proxy.$Proxy147.getResultSet(Unknown Source)at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getFirstResultSet(DefaultResultSetHandler.java:237)at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:187)at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65)at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)at sun.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)at com.sun.proxy.$Proxy145.query(Unknown Source)at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)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:65)at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)at com.sun.proxy.$Proxy144.query(Unknown Source)at sun.reflect.GeneratedMethodAccessor193.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)at com.sun.proxy.$Proxy144.query(Unknown Source)at com.github.pagehelper.util.ExecutorUtil.executeAutoCount(ExecutorUtil.java:166)at com.github.pagehelper.PageInterceptor.count(PageInterceptor.java:157)at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:100)at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)at com.sun.proxy.$Proxy144.query(Unknown Source)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)... 129 common frames omitted

二、 原因

一开始我还以为Mybatis的问题也是糊涂啊,没仔细看报错代码 ,找了半天,各种debug 最后看到 走到了shardingsphere 的源码中报错了。最后还发现是分表查询的时候会有一个组合的过程,然后比如我发生的问题 alert_info 表 与 alert_info2022(无数据) 结果集组合的过程 发生了异常。

使用shardingsphere 4.0.0-RC1 版本

 org.apache.shardingspheresharding-jdbc-spring-boot-starter4.0.0-RC1org.apache.shardingspheresharding-jdbc-spring-namespace4.0.0-RC1

三、解决方法

换个 shardingsphere 版本
这里我将 4.0.0-RC1 换成了 4.1.1

org.apache.shardingspheresharding-jdbc-spring-boot-starter4.1.1

4.1.1 版本 与 4.0.0-RC1 有些差异需要注意

druid 需要单独引入 不能使用 druid-spring-boot-starter 会报错 DataSource注入失败的问题

  com.alibabadruid1.2.6

配置文件不需要在配置 Mysql 数据源这些配置 因为在shardingsphere 配置中 也会配置数据源这些操作
在这里插入图片描述

四、总结

发生异常的时候一定要看仔细报错原因例如 我截图的 就能大概知道是 shardingsphere框架的问题。
在这里插入图片描述

确认框架问题后,发生查不到的异常原因或者各种无法解决的异常 尝试将框架版本升级一下试试。 毕竟框架也是在一步步完善中

如果对你有帮助,加个关注把~
在这里插入图片描述

相关内容

热门资讯

AWSECS:访问外部网络时出... 如果您在AWS ECS中部署了应用程序,并且该应用程序需要访问外部网络,但是无法正常访问,可能是因为...
AWSElasticBeans... 在Dockerfile中手动配置nginx反向代理。例如,在Dockerfile中添加以下代码:FR...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...
北信源内网安全管理卸载 北信源内网安全管理是一款网络安全管理软件,主要用于保护内网安全。在日常使用过程中,卸载该软件是一种常...
AWR报告解读 WORKLOAD REPOSITORY PDB report (PDB snapshots) AW...
AWS管理控制台菜单和权限 要在AWS管理控制台中创建菜单和权限,您可以使用AWS Identity and Access Ma...
​ToDesk 远程工具安装及... 目录 前言 ToDesk 优势 ToDesk 下载安装 ToDesk 功能展示 文件传输 设备链接 ...
群晖外网访问终极解决方法:IP... 写在前面的话 受够了群晖的quickconnet的小水管了,急需一个新的解决方法&#x...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
Azure构建流程(Power... 这可能是由于配置错误导致的问题。请检查构建流程任务中的“发布构建制品”步骤,确保正确配置了“Arti...