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"); } }
Anonymous
Database changes rollback; counter remains changed. Initial counter = 0 After execution = 1
Check out your Company Bowl for anonymous work chats.