IBM interview question

Counter value incremented inside transaction. If transaction fails, class value updated? @Service public class PaymentService { private int counter = 0; @Transactional public void processPayment() { counter++; paymentRepository.save(payment); throw new RuntimeException("Failed"); } }

Interview Answer

Anonymous

6 Jun 2026

Database changes rollback; counter remains changed. Initial counter = 0 After execution = 1