I have a requirement where I need my nested transaction to be a new transaction so that only current transaction will roll-back in case of exception not caller one and I also want to get the saved entity in nested transaction which were saved in upper level transaction.
@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void A(){
//saving entity x
B();
}
@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = **Propagation.REQUIRES_NEW**, rollbackFor = Exception.class)
public void B(){
//saving some other entity
//fetch previously created entity x
}
Now the problem is When I try to fetch the entity x in B() which was saved in A(), I don't get this.
But If I change the transaction type of B() from Propagation.REQUIRES_NEW to Propagation.REQUIRED it works. Problem in this case is if transaction B is rolled back, transaction A will too, but this is not intended. Please suggest some solution that will solve both of the use-case.