当前使用版本(必须填写清楚,否则不予处理)

com.baomidou mybatis-plus-boot-starter 3.2.0 org.apache.shardingsphere sharding-jdbc-core 4.0.0-RC2

该问题是怎么引起的?(最新版上已修复的会直接close掉)

使用sharding-jdbc-core数据源,mybatis-plus进行分页查询报错类型转换错误

重现步骤

使用sharding-jdbc-core数据源,mybatis-plus进行分页查询报错类型转换错误 自定义实现com.baomidou.mybatisplus.core.metadata.IPage;, 将 private long size;private long current; 修改为int 类型可以修复这个问题,但没有进行覆盖测试,不知道是否会引起其他问题

报错信息

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

The error may exist in com/shinelon/sharding/sphere/mapper/PtTradeCommonOrderMapper.java (best guess)

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: SELECT id, interests_amount, order_create_time, interests_code, vip_uuid, app_code, interests_status, cumulative, benchmark, core_order_no, trade_amount, base_rate, product_code, calc_points, create_time, interests_points, handle_status, interests_rate, trade_type, customer_no, channel_code FROM pt_trade_common_order LIMIT ?,?

Cause: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:78)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
at com.sun.proxy.$Proxy79.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForIPage(MybatisMapperMethod.java:115)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:86)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:61)
at com.sun.proxy.$Proxy81.selectPage(Unknown Source)
at com.shinelon.sharding.sphere.mapper.PtTradeCommonOrderMapperTest.selectPage(PtTradeCommonOrderMapperTest.java:50)
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.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

The error may exist in com/shinelon/sharding/sphere/mapper/PtTradeCommonOrderMapper.java (best guess)

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: SELECT id, interests_amount, order_create_time, interests_code, vip_uuid, app_code, interests_status, cumulative, benchmark, core_order_no, trade_amount, base_rate, product_code, calc_points, create_time, interests_points, handle_status, interests_rate, trade_type, customer_no, channel_code FROM pt_trade_common_order LIMIT ?,?

Cause: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

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 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)
... 37 more

Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer at org.apache.shardingsphere.core.optimize.sharding.segment.select.pagination.Pagination.getValue(Pagination.java:60) at org.apache.shardingsphere.core.optimize.sharding.segment.select.pagination.Pagination.(Pagination.java:54) at org.apache.shardingsphere.core.optimize.sharding.segment.select.pagination.engine.LimitPaginationEngine.createPagination(LimitPaginationEngine.java:40) at org.apache.shardingsphere.core.optimize.sharding.segment.select.pagination.engine.PaginationEngine.createPagination(PaginationEngine.java:50) at org.apache.shardingsphere.core.optimize.sharding.engnie.dml.ShardingSelectOptimizeEngine.optimize(ShardingSelectOptimizeEngine.java:63) at org.apache.shardingsphere.core.optimize.sharding.engnie.dml.ShardingSelectOptimizeEngine.optimize(ShardingSelectOptimizeEngine.java:47) at org.apache.shardingsphere.core.route.router.sharding.ParsingSQLRouter.route(ParsingSQLRouter.java:72) at org.apache.shardingsphere.core.route.PreparedStatementRoutingEngine.route(PreparedStatementRoutingEngine.java:66) at org.apache.shardingsphere.core.PreparedQueryShardingEngine.route(PreparedQueryShardingEngine.java:60) at org.apache.shardingsphere.core.BaseShardingEngine.executeRoute(BaseShardingEngine.java:86) at org.apache.shardingsphere.core.BaseShardingEngine.shard(BaseShardingEngine.java:70) at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.shard(ShardingPreparedStatement.java:224) at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.execute(ShardingPreparedStatement.java:170) 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.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) at com.sun.proxy.$Proxy96.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) 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.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) at com.sun.proxy.$Proxy95.query(Unknown Source) at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doQuery(MybatisSimpleExecutor.java:67) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) 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.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) at com.sun.proxy.$Proxy94.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ... 43 more

Comment From: miemieYaho

你去让他支持long

Comment From: cc-cfg

Cause: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

您好,问一下 现在这个问题你是怎么解决的?

Comment From: haoyousb

我也遇到了,报错信息也不明显,检查半天才查到问题,有什么解决办法么? @miemieYaho

Comment From: shaoxiong789

这个是shardingsphere的坑,我也遇到了

Comment From: xhye

请问解决了吗