0

I want to make operations performed by crud repository of jpa as part of xa transactions i.e. they should be committed when xa resource is committed.

Following is the code in which save method uses xa resource and saveTeam method uses crud repository method i.e. save. I have tried transaction propagation supported, not_supported, etc parameters but didn't worked

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. currently changes are visible in db when save method is executed in save Team method.

1 Answers1

0

add this line spring.jpa.show-sql=true in your application.properties file