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框架的问题。
在这里插入图片描述

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

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

相关内容

热门资讯

前端-session、jwt 目录:   (1)session (2&#x...
linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
关于测试,我发现了哪些新大陆 关于测试 平常也只是听说过一些关于测试的术语,但并没有使用过测试工具。偶然看到编程老师...
前缀和与对数器与二分法 1. 前缀和 假设有一个数组,我们想大量频繁的去访问L到R这个区间的和,...
nodejs:本地安装nvm实... 一、背景-使用不同版本node的原因 vue3+ts、nuxt3版本,node...
JAVA集合知识整理 Java集合知识整理 HashMap相关 HashMap的底层数据结构:jdk1.8之...
无刷直流电机介绍及单片机控制实... 无刷直流电机介绍及单片机控制实例前言基本概念优势与劣势使用寿命基本结构使用单片机控制实例电子调速器&...
fwdiary(2) dp2 1.传纸条  AcWing 275. 传纸条 - AcWing 走两条路,走一条最大的...
常用的DOS命令 常用的DOS命令 DOS(Disk Operating System,磁...
<C++> 类和对象(下) 1.const成员函数将const修饰的“成员函数”称之为const成员函数,cons...