SteelReed

Search

Search posts, questions…

Transactions & LockingQuestion 14 / 17

Middle

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.

RuntimeException, Errordone, or checked exceptionskips proxyAnother bean calls placeProxy opens transactionMethod runsRollbackCommitthis.place in classNo transaction

3 points to say:

  1. this.method() gets no transaction.
  2. Checked exceptions commit by default.
  3. timeout doesn'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.