jpa - EJB3 事务 REQUIRES_NEW 未提交
问题描述
我在 EJB3/JTA 事务和事务隔离方面遇到了一些问题。
我正在使用 WildFly 17。
我有一个无状态 EJB 方法,它从另一个 EJB 调用不同的方法。
我希望使用 REQUIRES_NEW 每个方法都有自己的事务,并且每个方法都会提交到数据库。
所以下一个方法可以查看和使用之前插入或更新的数据库中的数据。
但事实并非如此。在 test3() 中,我看不到/使用来自 test1() 和 test2() 的数据。
我已经阅读了许多有关此行为的其他问题和答案,但没有一个帮助我找到解决此问题的方法。
这是我的问题的伪代码。
@Stateless
public class A {
@Inject IAnotherEJB service;
public test() {
service.test1();
//here, in the "main method" i can see X from the database
service.test2();
//here, in the "main method" i can see X and Z from the database
service.test3();
}
}
@Stateless
public class AnotherEJB implements IAnotherEJB {
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public test1() {
...
//add X and update Y to the database (JPA)
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public test2() {
...
//add/update other some data Z to the database (JPA)
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public test3() {
...
//find X and Z from the database (JPA finById)
//Here i can't see X or Z in the database or i have some error : Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) about Y
...
//add/update other some data W to the database (JPA) using X and Z
}
}
像这样使用 REQUIRES_NEW 有什么问题吗?
解决方案
推荐阅读
- javascript - 在终端上获取错误缺少模块
- angular - 如何从父组件传递到未嵌套的子组件?
- swift - 如何在没有纹理图集的 spritekit 中创建此动画
- matlab - Matlab onehot转整数
- javascript - 停止后如何重新启动网络工作者
- python - 在 Python 中公开序列化函数
- parallel-processing - 将 gnu 的输出并行传输到单个文件或管道是否安全
- flume - 边缘节点上的 Apache Flume 设置说明
- c - Printf 不立即打印,虽然缓冲被禁用
- raku - Perl 6 Cro 的存根不运行:请求 HTTP/2,但不支持 ALPN