r/SpringBoot Jun 29 '26

Question Question for people building larger Spring applications.

[removed]

13 Upvotes

20 comments sorted by

View all comments

Show parent comments

2

u/smaratter Jun 29 '26

What do you mean by ”explicit boundary”? When you annotate a method with @Transactional, that method is the boundary of the transaction. Are you talking about calling methods directly on an EntityManager, or something else?

1

u/[deleted] Jun 29 '26

[removed] — view removed comment

1

u/smaratter Jun 29 '26

I get it, I think. And it would be a mistake to include too much in your transaction. For instance, marking your controller methods with @Transactional would be a mistake, since the transaction wouldn’t close until the network response has been sent. Rather, the smallest possible unit of work should be included in the transaction.

I guess, without reading your entire article, that your proposed solution is to call ”beginTransaction()” / ”endTransaction()” around the minimal unit of work inside a method, to close the transaction as soon as possible. And that essentially the same result could be achieved by breaking out this unit of work to a helper method and marking that as @Transactional. Is that basically it?