itxiaole opened a new issue #3786: The spring boot project queries across libraries URL: https://github.com/apache/incubator-shardingsphere/issues/3786 Problem description :order and order_item are in different libraries Query error There was an error using the selectOrderAndOrderItem method org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 ### The error may exist in com/sharding/jdbc/jdbc/kuakuguanlianquery/TOrder.java (best guess) ### The error may involve com.sharding.jdbc.jdbc.kuakuguanlianquery.TOrder.selectOrderAndOrderItem ### The error occurred while handling results ### SQL: select count(1) from t_order a LEFT JOIN t_order_item b on a.order_id=b.order_id ### Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440) at com.sun.proxy.$Proxy76.selectOne(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:93) at com.sun.proxy.$Proxy80.selectOrderAndOrderItem(Unknown Source) at com.sharding.jdbc.jdbc.kuakuguanlianquery.OrderDaoTest.settOrder(OrderDaoTest.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 ### The error may exist in com/sharding/jdbc/jdbc/kuakuguanlianquery/TOrder.java (best guess) ### The error may involve com.sharding.jdbc.jdbc.kuakuguanlianquery.TOrder.selectOrderAndOrderItem ### The error occurred while handling results ### SQL: select count(1) from t_order a LEFT JOIN t_order_item b on a.order_id=b.order_id ### Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at 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 org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 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) ... 36 more @Insert("INSERT INTO t_order (`price`, `user_id`, `status`) VALUES (1, #{userId}, '1')") void insert(@Param("userId")Long userId); @Select("select count(1) from t_order a LEFT JOIN t_order_item b on a.order_id=b.order_id") int selectOrderAndOrderItem(); <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>sharding-jdbc-spring-boot-starter</artifactId> <version>4.0.0-RC1</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.10</version> </dependency> spring.shardingsphere.datasource.names=m1,m2 #type必须要用不然NPE spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource spring.shardingsphere.datasource.m1.driver-class-name= com.mysql.jdbc.Driver spring.shardingsphere.datasource.m1.url= jdbc:mysql://localhost:3306/order_db?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8 spring.shardingsphere.datasource.m1.username= root spring.shardingsphere.datasource.m1.password= xiaole #type必须要有type不然启动NPE spring.shardingsphere.datasource.m2.type=com.alibaba.druid.pool.DruidDataSource spring.shardingsphere.datasource.m2.driver-class-name= com.mysql.jdbc.Driver spring.shardingsphere.datasource.m2.url= jdbc:mysql://localhost:3306/order_item_db?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8 spring.shardingsphere.datasource.m2.username= root spring.shardingsphere.datasource.m2.password= xiaole spring.shardingsphere.sharding.tables.t_order.actual-data-nodes=m1.t_order_$->{1..2} #主键id spring.shardingsphere.sharding.tables.t_order.key-generator.column=order_id #主键生成策略 雪花算法 spring.shardingsphere.sharding.tables.t_order.key-generator.type=SNOWFLAKE #表达式分片策略 #分片列名称#分片列名称 spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.sharding-column=order_id #分片算法行表达式,需符合groovy语法 spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.algorithm-expression=t_order_$->{order_id % 2 + 1} #主节点 spring.shardingsphere.sharding.tables.t_order_item.actual-data-nodes=m2.t_order_item_$->{1..2} #主键id spring.shardingsphere.sharding.tables.t_order_item.key-generator.column=order_id #主键生成策略 雪花算法 spring.shardingsphere.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE #分库策略,缺省表示使用默认分库策略,以下的分片策略只能选其一 #表达式分片策略 #分片列名称#分片列名称 spring.shardingsphere.sharding.tables.t_order_item.table-strategy.inline.sharding-column=order_id #分片算法行表达式,需符合groovy语法 spring.shardingsphere.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item_$->{order_id % 2 + 1} #是否开启SQL显示,默认值: false spring.shardingsphere.props.sql.show=true
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services