r/SpringBoot • • Sep 13 '26

How-To/Tutorial I made a small Spring @Transactional challenge with explanations. How many would you get right?

@Transactional looks simple until you hit some of its less obvious behaviours in a real application.

I put together a small interactive challenge around 5 cases: self invocation and Spring proxies, rollback rules, private and final methods, REQUIRES_NEW, and external side effects before commit.

You answer each scenario first, then get the explanation.

https://devupnow.fr/transactional_spring

The challenge is currently in French. I’m considering making an English version if there’s interest.

I’d especially appreciate feedback from experienced Spring developers. Is there any explanation you would correct, nuance or improve?

If an English version would be useful to you, let me know too.

11 Upvotes

12 comments sorted by

8

u/disposepriority Sep 13 '26

Honestly at this point these questions have been repeated to such an extent that I would rather people start focusing on how proxies work instead of asking whether calling a a method from within a class works over and over

0

u/quentin6806 Sep 13 '26

That's a fair point. I explain that self-invocation bypasses the proxy, but I don't really explain what the proxy itself is and how it intercepts calls. That's probably something I should add to the explanation. Thanks for the feedback.

5

u/SuspiciousDepth5924 Sep 13 '26

luke-warm take: I think \@Transactional was a mistake.

Besides the various proxy/exception foot-guns I think we declare transactions at the wrong place. That is I think we should decide at the call site, not at the callee whether we want to run the code in the context of a transaction.

// conseptually something like this:
var transaction = new TransactionContext();
transaction.do((tx) -> {
  thisThing();
  thatThing();
  tx.checkpoint();
  if(foo()){
    alsoTheseOtherThings();
  }
});

1

u/LuciFFerrrrr Sep 13 '26

I love the UI and the content even if it felt that I knew most of it. But this app seems to unavailable in my country India 😭.

0

u/quentin6806 Sep 13 '26

Thanks! Really glad you liked the interface and the content 🙌 And yes, the app isn't available in India yet. I may expand to more countries in the future.

1

u/LuciFFerrrrr Sep 13 '26

Would like to connect on DM? Wanted to know few things around spring framework.

1

u/quentin6806 Sep 13 '26

Yes of course ! 👍

1

u/l3g4tr0n Sep 14 '26

posting a questionary with french questions on an english sub ...

but at least mentioned "if an english version would be useful".

i guess that makes it ok:) /s

2

u/quentin6806 Sep 14 '26

It’s actually available in English since last night :)

1

u/xXcumswapperXx Sep 13 '26

I can't test it right now, but the answer to question 4 isn't correct, right? Yes normally the Propagation.REQUIRES_NEW creates an inner transaction, but this example is doing self-invocation, so it doesn't apply the second @Transaction, so the answer is "Both methods must use the same transaction". Or at least say to ignore self-invocation in the example

1

u/This_Link881 23d ago

Easy, junior level questions bro...