Card 06/ 07
All 7 cards
ExerciseDifficulty: Advanced1 min
Will It Roll Back?
A @Transactional method saves a row, calls a payment gateway that throws PaymentDeclinedException (a checked exception), and does nothing else. Does the save roll back? What line would change the answer?
See the answer
No, it commits — checked exceptions don't roll back by default, the same as MyCheckedException in the gotcha card. Adding @Transactional(rollbackFor = PaymentDeclinedException.class) to the method is what would make it roll back instead.