In my understanding newPrint
method in the following code should create a new transaction but apparently it prints out the same transaction-status object as was used in oldPrint
method. I am calling oldPrint from another class. Is it because newPrint is being called using this
? If yes, then when will a new transaction get created? If I call both methods from another class two separate transaction will be created anyway because @Transactional
is used at class level.
@Transactional
public class Unsubcriber {
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void newPrint() {
System.out.println(TransactionAspectSupport.currentTransactionStatus());
}
public void oldPrint() {
System.out.println(TransactionAspectSupport.currentTransactionStatus());
newPrint();
}
Output:
org.springframework.transaction.support.DefaultTransactionStatus@3bacd0e7
org.springframework.transaction.support.DefaultTransactionStatus@3bacd0e7
What would be the scenario when Propagation.REQUIRES_NEW
would work?