The repository now aggregates two independent modules. migration-behavior/ is the
original project, moved unchanged; it stays on Spring Boot 4.0.6 / JDK 21 because
that is what the four published migration articles were verified against, and
upgrading it would silently invalidate output they quote. The article-tagged trees
are untouched, so links into a tag are unaffected.
transactions/ Companion code for "@Transactional in Spring: Propagation, Isolation,
and the Six Ways It Silently Does Nothing". Spring Boot 4.1.1 / JDK 25.
Every row of the propagation matrix is produced by calling the method and asking the
transaction manager what it did. The transaction NAME is the exhibit: a scope that
joined reports its caller's name, a scope that started its own reports its own.
Three things the transcripts settle:
- Propagation.NESTED cannot be used with JpaTransactionManager. It fails twice,
with two different messages, the second of which blames your JPA provider. The
savepoint manager comes from the object the JpaDialect returns when it begins the
transaction, and Hibernate's does not implement one. It works on
DataSourceTransactionManager, because a savepoint is a JDBC concept -- shown
working there rather than only failing here.
- Catching a REQUIRED inner failure does not save the transaction. The inner scope
has already marked it rollback-only, so the commit throws
UnexpectedRollbackException from a place with no connection to the cause.
- A checked exception commits, and so does a swallowed one. Those two do not merely
fail to start a transaction; they commit work the code was abandoning.
19 contract tests, six captured transcripts, all regenerated by scripts/run-all.sh.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gip4srpzMwjgoba6uEfbr5
33 lines
1.4 KiB
Bash
Executable File
33 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Does the inner write survive when the outer transaction fails? And what happens when the
|
|
# caller catches the inner exception?
|
|
set -euo pipefail
|
|
set +m
|
|
cd "$(dirname "$0")/.."
|
|
source scripts/env.sh
|
|
{
|
|
echo "== rollback behaviour =="
|
|
echo
|
|
start_app > /dev/null
|
|
curl -s "http://127.0.0.1:${APP_PORT}/tx/rollback" | python3 -c '
|
|
import json,sys
|
|
for k,v in json.load(sys.stdin).items():
|
|
print(" %s" % k)
|
|
print(" outcome : %s" % v["outcome"])
|
|
if "message" in v: print(" message : %s" % v["message"])
|
|
print(" rows : %s -> %s" % (v["auditRowsSurviving"], v["verdict"]))
|
|
print()'
|
|
echo "The third and fourth rows are the ones worth sitting with."
|
|
echo
|
|
echo "When a REQUIRED inner scope throws, it marks the SHARED transaction rollback-only"
|
|
echo "before the exception leaves it. The caller can catch the exception -- and does, and"
|
|
echo "returns normally -- but the transaction is already doomed, so the commit at the end"
|
|
echo "throws UnexpectedRollbackException. Catching the exception did not save the work; it"
|
|
echo "only moved the failure to a place with no useful stack trace."
|
|
echo
|
|
echo "With REQUIRES_NEW the inner scope had its own physical transaction, so its rollback"
|
|
echo "is contained and the caller's catch behaves the way the code reads."
|
|
stop_app
|
|
} > docs/output/02-rollback.txt 2>&1
|
|
cat docs/output/02-rollback.txt
|