My method calls are like follow.
@TransactionAttribute(TransactionAttributeType.SUPPORTS
void M1() {
M2();
M3();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
void M2(){
//saving x on data base
}
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
void M3(){
//accessing x from data base
}
The issue is, some times value x is unavailable at method M3.
Can any body say whats the possible issue here ?
There are two cases in your example, result is depending on whether is transaction already started in M1
or not, let me show you how it works
public void M1() {
//transaction doesn't exist now
M2();
//transaction context has been created and ended due to REQUIRED attribute
M3();
//now you see result in DB because it was commited in M2s transaction
}
public void M1() {
//transaction already exists from method which called M1
M2();
//joins the transactional context
M3(); //gets attached to the same context
// and now whole transaction gets commited and only now you can be sure that you can read from DB safely
}
I hope it's helpful for you, solution would be marking M1
REQUIRED as well.