#350 UnexpectedRollbackException When Catching an Exception
Explain how the code works:
@Component
class Bean1 {
@Autowired
private Bean2 bean2;
@Autowired
private EntityRepository entityRepository;
@Transactional
public void save() {
Entity entity = new Entity();
try {
bean2.doIt(entity);
} catch (Exception ex) {
log.error("Error", ex);
}
entityRepository.save(entity);
}
}
@Component
class Bean2 {
@Transactional
public void doIt(Entity entity) {
throw new RuntimeException();
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor