[英]How to integrate operations of jpa repository methods i.e. save into xa resource transactions?
I want to make operations performed by crud repository of jpa as part of xa transactions ie they should be committed when xa resource is committed. 我想使由jpa的crud存储库执行的操作作为xa事务的一部分,即,在提交xa资源时应提交它们。
Following is the code in which save method uses xa resource and saveTeam method uses crud repository method ie save. 以下是其中save方法使用xa资源,而saveTeam方法使用crud存储库方法(即save)的代码。 I have tried transaction propagation supported, not_supported, etc parameters but didn't worked 我已经尝试了支持事务传播,not_supported等参数,但是没有用
public boolean save() throws Exception {
OracleXADataSource oracleRootSource = new OracleXADataSource();
oracleRootSource.setUser("root");
oracleRootSource.setPassword("root");
oracleRootSource.setURL("jdbc:oracle:thin:@localhost:1521:xe");
XADataSource xaDS = oracleRootSource;
XAConnection xaCon = xaDS.getXAConnection("root", "root");
XAResource xaRes = xaCon.getXAResource();
Connection con = xaCon.getConnection();
Statement stmt = con.createStatement();
Xid xid = new MyXid(100, new byte[] { 0x01 }, new byte[] { 0x02 });
xaRes.start(xid, XAResource.TMJOIN);
// stmt.executeUpdate("Insert into school values ( " + 202 + ", 'Second')");
this.saveTeam(new Team("second"));
xaRes.end(xid, XAResource.TMSUCCESS);
return true;
}
@Transactional(propagation = Propagation.MANDATORY)
public Team saveTeam(Team team) {
Team te = repo.save(team);
return te;
}
I want to see changes done by saveTeam method when xresource is commited. 我想查看在提交xresource时,通过saveTeam方法所做的更改。 currently changes are visible in db when save method is executed in save Team method. 在save Team方法中执行save方法时,当前更改在db中可见。
在application.properties文件中添加spring.jpa.show-sql=true
这行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.