What are the @Transactional pitfalls: self-invocation, checked exceptions, readOnly and timeout?
Short answer
@Transactional works through a proxy (a wrapper around the bean), so calling a method in the same class (this.save()) bypasses the proxy and gets no transaction. By default it rolls back only on RuntimeException and Error: checked exceptions still commit.
3 points to say:
this.method()gets no transaction.- Checked exceptions commit by default.
timeoutdoesn't stop running Java code.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.