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

柔性事务中ShardingPreparedStatement多次调用executeUpdate()问题 #134

Closed
Beyondeclipse opened this issue Aug 16, 2016 · 2 comments

Comments

@Beyondeclipse
Copy link

Beyondeclipse commented Aug 16, 2016

在1.3.1版本中,因柔性事务要autoCommit,所以对于批量插入时,只能使用类似如下的方式提交:

transaction.begin(conn);
for(User u : userList){
  pstm.setString(1, u.getName());
  pstm.setInt(2, u.getCode());
  hintManager.addDatabaseShardingValue("test", "user_id", u.getUserId); 

  pstm.executeUpdate();
  pstm.clearParameters();
}
transaction.end();

在ShardingPreparedStatement#executeUpdate()中

@Override
    public int executeUpdate() throws SQLException {
        hasExecuted = true;
        return new PreparedStatementExecutor(getShardingConnection().getShardingContext().getExecutorEngine(), getRoutedPreparedStatements()).executeUpdate();
    }

其中 getRoutedPreparedStatements()会因为hasExecuted = true;反复使用相同的cachedRoutedPreparedStatements,导致插入的值都相同且在同一分片中

@Beyondeclipse
Copy link
Author

其他的方法如execute也有类似问题。

@hanahmily
Copy link
Contributor

该问题与 #36 相同,已经在1.3.2版本中得到了修复

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

3 participants