简体   繁体   English

如何集成jpa存储库方法的操作,即保存到xa资源事务中?

[英]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.

相关问题 JMS 和 JPA 没有两阶段提交的事务(即不支持 JTA) - JMS and JPA transactions without two phase commit (i.e. JTA is not supported) 如何使用@Query 向标准 CRUD Spring JPA 存储库方法添加其他方法(例如按名称、角色、类别搜索)? - How To Add Additional Methods To Standard CRUD Spring JPA Repository Methods Using @Query (e.g. Search By Name, Role, Category)? 无法从 SpringBoot Main 方法保存 JPA Repository 变量的方法 - Methods of JPA Repository variable not able to save from SpringBoot Main method 如何在 JPA 存储库中的自定义方法中使用规范 - How to use Specification in custom methods in JPA Repository Spring Data JPA:为什么保存该实体会按预期进行(即,很高兴父级不会被覆盖)? - Spring Data JPA: Why does saving this entity work as intended (i.e. parent is thankfully not overwritten)? 如何处理 JPA Repository 查询方法中的多个字段? - How to handle multiple fields in JPA Repository query methods? 带有Spring Boot的Spring Security 4:静态资源(即CSS,JS,IMG)404问题 - Spring Security 4 with Spring Boot: static resource (i.e. css, js, img) 404 issue 如何在JPA存储库方法中使用部分复合键来获取数据? - How to use part of composite key in JPA repository methods to fetch data? 如何在jpa存储库自定义方法上应用搜索条件(规范)? - How to apply search criteria (specification) on jpa repository custom methods? JVM 如何知道我们自己的方法在 Jpa 存储库中的实现? - How the JVM will know the implementation of our own methods in the Jpa Repository?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM