#449 Transaction Rollback After a Caught Exception

Companies:
Raiffeisenbank
Themes:
SpringTransactionsCode Review

What happens to database changes after the catch block?

@Service
public class A {

    @Autowired
    B b;

    @Transactional
    public void doStuff() {
        try {
            b.doStuff();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // do some stuff
    }

}

@Service
public class B {

    @Transactional
    public void doStuff() {
        // do some stuff
        throw new RuntimeException();
    }

}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in