I'm having some troubles with EJB3/JTA transaction and transaction isolation.
I'm using WildFly 17.
I have a stateless EJB method that call different method from another EJB.
I was hopping that using REQUIRES_NEW each method will have it's own transaction, and each method will make a commit to the database.
So the next method can see and use data from the database inserted or updated before.
But it's not like this. in test3() i can't see/use data from test1() and test2().
I've read many other questions and answer about this behavior, but none helped me to find a solution to this problem.
Here is a pseudo code of my problem.
@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
}
}
Is there something wrong using REQUIRES_NEW like this ?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…