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

why the xa transaction does not work? #31121

Open
gejing1108 opened this issue May 5, 2024 · 0 comments
Open

why the xa transaction does not work? #31121

gejing1108 opened this issue May 5, 2024 · 0 comments

Comments

@gejing1108
Copy link

version: 5.4.1

<dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-transaction-xa-core</artifactId>
        </dependency>

I've followed the github step to generate the examples for shardingsphere
image
and in this example, it runs the named run method to implement xa transaction, while I don't find any annotation on this method, this method only create table, insert records and then drop tables, so I doubt if it can show the function of xa transaction, I've tested in my way:
first, add the transaction type in config file as the sample do:
image
and then add the bean class as the sample do:
image
and then import it as the sample do:
image
and at last, I write a simple method to test it:

@Operation(summary = "测试XA事务")
  @PostMapping("/saveContractForXA")
  public ResponseResult<Void> saveContractForXA() {
    for (int i = 0; i < 10; i++) {
      if (i == 6) {
        int j = 8 / 0;
      }

      ContractEntity contract = new ContractEntity();
      contract.setContractName(RandomUtil.randomString(8));
      contractMapper.insert(contract);
    }

    return ResponseResult.success();
  }

in this method, I throw an exception when I've inserted 6 records, if the xa transaction works, it will rollback when the exception appears, while actually, 6 records are inserted into the table, so what have I omitted for xa transaction?

btw: in old version of shardingsphere like 4.X, I should add annotation like @ShardingTransactionType(value = TransactionType.XA), while in the 5.X version, I don't find this annotation, and in the sample generated above, I don't find any annotation on the method

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

No branches or pull requests

1 participant