Skip to content

Use Statement.executeBatch() Api To InsertBatch Cannot generate UndoLog #4833

@a1104321118

Description

@a1104321118
  • I have searched the issues of this repository and believe that this is not a duplicate.

Ⅰ. Issue Description

使用 myabtis-plus 的 saveBatch时,无法回滚插入的数据;

原因是 该方法底层调用了 Statement.executeBatch() 方法,该方法无法返回影响的行数; 原因: https://forums.mysql.com/read.php?39,699815,699821#msg-699821

而 seata 1.5.1 版本,生成后镜像的时候做了如下判断,由于updateCount 没有大于0,所以导致不去生成 undolog

// io.seata.rm.datasource.exec.AbstractDMLBaseExecutor#executeAutoCommitFalse

TableRecords beforeImage = beforeImage();
        T result = statementCallback.execute(statementProxy.getTargetStatement(), args);
        int updateCount = statementProxy.getUpdateCount();
        if (updateCount > 0) {
            TableRecords afterImage = afterImage(beforeImage);
            prepareUndoLog(beforeImage, afterImage);
        }

seata 0.9.0 没有这个问题,因为0.9.0 没有做这个判断

Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

Just paste your stack trace here!

Ⅲ. Describe what you expected to happen

能否优化一下这里的判断?

Ⅳ. How to reproduce it (as minimally and precisely as possible)

  1. 开启全局事务
  2. 构建1个以上的 DO 对象
  3. 开启本地事务
  4. 使用 mybatis-plus 的 saveBatch 方法,插入数据
  5. 提交本地事务
  6. 抛异常回滚全局事务
  7. 发现插入的对象没有被回滚

如果不用 mybatis-plus 的 saveBatch 方法;改成自己写 xml 批量插入; insert xx values (xx),(xx); 能正常回滚

Ⅴ. Anything else we need to know?

Ⅵ. Environment:

  • JDK version : 1.8
  • Seata version: 1.5.1
  • OS :
  • Others:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions