Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sharding-sphere3.0.0+mybatisplus2.1.4+mysql, batchInsert error, help me !!! #8577

Closed
guid-git opened this issue Dec 11, 2020 · 6 comments
Closed

Comments

@guid-git
Copy link

Question

Error flushing statements. Cause: java.lang.ArrayIndexOutOfBoundsException: 1

Cause: java.lang.ArrayIndexOutOfBoundsException: 1

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:255)
at com.baomidou.mybatisplus.service.impl.ServiceImpl.insertBatch(ServiceImpl.java:131)
... 37 common frames omitted

Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at io.shardingsphere.shardingjdbc.executor.BatchPreparedStatementExecutor.accumulate(BatchPreparedStatementExecutor.java:176)
at io.shardingsphere.shardingjdbc.executor.BatchPreparedStatementExecutor.executeBatch(BatchPreparedStatementExecutor.java:168)
at io.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.executeBatch(ShardingPreparedStatement.java:236)

@guid-git guid-git changed the title sharding-sphere3.0.0+mybatisplus2.1.4+mysql, batchInsert error sharding-sphere3.0.0+mybatisplus2.1.4+mysql, batchInsert error, help me !!! Dec 11, 2020
@guid-git
Copy link
Author

private int[] accumulate(final List<int[]> results) {
int[] result = new int[batchCount];
int count = 0;
for (BatchRouteUnit each : routeUnits) {
for (Entry<Integer, Integer> entry : each.getJdbcAndActualAddBatchCallTimesMap().entrySet()) {
### int value = null == results.get(count) ? 0 : results.get(count)[entry.getValue()];
if (DatabaseType.Oracle == getDatabaseType()) {
result[entry.getKey()] = value;
} else {
result[entry.getKey()] += value;
}
}
count++;
}
return result;
}

@terrymanu
Copy link
Member

terrymanu commented Dec 12, 2020

I don't know what is mybatis-plus, could you get the actual SQL and jdbc method?

@qixiaobo
Copy link

I don't know what is mybatis-plus, could you get the actual SQL and jdbc method?

It's a framework based on mybatis https://github.com/baomidou/mybatis-plus (MyBatis-Plus is an powerful enhanced toolkit of MyBatis for simplify development. This toolkit provides some efficient, useful, out-of-the-box features for MyBatis, use it can effectively save your development time.).
Maybe @guid-git should provide more info

@guid-git
Copy link
Author

for example, i call mybatis-plus's method ExampleService.insertBatch(list). when list's size is 10, sharding-sphere will put the same table data in one sql. such like '' insert into table values(),()"". then look the method i said above "accumulate", each.getJdbcAndActualAddBatchCallTimesMap().entrySet() ’s size is 2。but when i debug the param "final List<int[]> results" of the method "accumulate" , i get the param int[] 'size is 1, so throw java.lang.ArrayIndexOutOfBoundsException:1

@RaigorJiang
Copy link
Contributor

It is recommended that you first check whether the SQL is correct, so please provide your actual SQL, not the Java code.

@terrymanu
Copy link
Member

Closed because of no response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants