![](/img/trans.png)
[英]JMS and JPA transactions without two phase commit (i.e. JTA is not supported)
[英]How to integrate operations of jpa repository methods i.e. save into xa resource transactions?
我想使由jpa的crud存儲庫執行的操作作為xa事務的一部分,即,在提交xa資源時應提交它們。
以下是其中save方法使用xa資源,而saveTeam方法使用crud存儲庫方法(即save)的代碼。 我已經嘗試了支持事務傳播,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;
}
我想查看在提交xresource時,通過saveTeam方法所做的更改。 在save Team方法中執行save方法時,當前更改在db中可見。
在application.properties文件中添加spring.jpa.show-sql=true
這行
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.