mysql page limit Long parameter type error
See original GitHub issueBug Report
For English only, other languages will not accept.
Before report a bug, make sure you have:
- Searched open and closed GitHub issues.
- Read documentation: ShardingSphere Doc.
Please pay attention on issues you submitted, because we maybe need more details. If no response more than 7 days and we cannot reproduce it on current information, we will close it.
Please answer these questions before submitting your issue. Thanks!
Which version of ShardingSphere did you use?
4.0.0-RC2-SNAPSHOT(clone from dev branch)
Which project did you use? Sharding-JDBC or Sharding-Proxy?
Sharding-JDBC
Expected behavior
sql execute success
Actual behavior
Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
Reason analyze (If you can)
my code below: public List<User> findUsersByPageIntType(Integer begin, Integer end){ String sql = "select id,name,age,email from user limit ?,? "; Object[] params = new Object[] {begin, end}; List<User> userList = jdbcTemplate.query(sql, params, getUserMapper()); return userList; } public List<User> findUsersByPageLongType(Long begin, Long end){ String sql = "select id,name,age,email from user limit ?,? "; Object[] params = new Object[] {begin, end}; List<User> userList = jdbcTemplate.query(sql, params, getUserMapper()); return userList; }
first, call findUsersByPageIntType method, it’s ok but call findUsersByPageLongType method there was an error -> Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
1.application.properties spring.shardingsphere.datasource.names=ds0 spring.shardingsphere.datasource.ds0.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.ds0.jdbc-url=jdbc:mysql://127.0.0.1:3306/ttx_util?useUnicode=true&useSSL=false&characterEncoding=utf8 spring.shardingsphere.datasource.ds0.username=test spring.shardingsphere.datasource.ds0.password=test
spring.shardingsphere.sharding.tables.user.actual-data-nodes=ds0.user_$->{0…1}
spring.shardingsphere.sharding.tables.user.table-strategy.inline.sharding-column=erp_id
spring.shardingsphere.sharding.tables.user.table-strategy.inline.algorithm-expression=user_$->{erp_id % 2}
spring.shardingsphere.sharding.tables.user.key-generator.column=id
spring.shardingsphere.sharding.tables.user.key-generator.type=SNOWFLAKE
#是否开启SQL显示,默认值: false
spring.shardingsphere.props.sql.show=true
2.table create sql:
CREATE TABLE user_0 (
id bigint(20) NOT NULL COMMENT ‘主键ID’,
erp_id int(11) NOT NULL COMMENT ‘分表erpId’,
name varchar(30) DEFAULT NULL COMMENT ‘姓名’,
age int(11) DEFAULT NULL COMMENT ‘年龄’,
email varchar(50) DEFAULT NULL COMMENT ‘邮箱’,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE user_1 (
id bigint(20) NOT NULL COMMENT ‘主键ID’,
erp_id int(11) NOT NULL COMMENT ‘分表erpId’,
name varchar(30) DEFAULT NULL COMMENT ‘姓名’,
age int(11) DEFAULT NULL COMMENT ‘年龄’,
email varchar(50) DEFAULT NULL COMMENT ‘邮箱’,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Example codes for reproduce this issue (such as a github link).
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)

Top Related StackOverflow Question
I test in mysql 5.7.21, offset and row count of limit can be over INTEGER.MAX.
So, I think
Paginationin ShardingSphere should use type Long instead of Integer for offset and row count to solve this exception.Yes, you can clone dev branch and try with 4.0.0-RC3-SNAPSHOT again. And the new version is coming, please just wait.