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
47 lines
2.1 KiB
Bash
Executable File
47 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Can you actually use Propagation.NESTED with Spring Data JPA? Three attempts.
|
|
set -euo pipefail
|
|
set +m
|
|
cd "$(dirname "$0")/.."
|
|
source scripts/env.sh
|
|
{
|
|
echo "== attempt 1: a stock Spring Boot JPA application =="
|
|
echo "\$ java -jar $JAR"
|
|
echo
|
|
start_app > /dev/null
|
|
curl -s "http://127.0.0.1:${APP_PORT}/tx/propagation" | python3 -c '
|
|
import json,sys
|
|
v=json.load(sys.stdin)["NESTED"]["withOuterTransaction"]
|
|
print(" " + v.get("exception","(no exception)"))
|
|
print(" " + v.get("message",""))'
|
|
echo
|
|
echo "== attempt 2: nestedTransactionAllowed = true, as the message instructs =="
|
|
echo "\$ java -jar $JAR --demo.nested-allowed=true"
|
|
echo
|
|
start_app --demo.nested-allowed=true > /dev/null
|
|
curl -s "http://127.0.0.1:${APP_PORT}/tx/propagation" | python3 -c '
|
|
import json,sys
|
|
v=json.load(sys.stdin)["NESTED"]["withOuterTransaction"]
|
|
print(" " + v.get("exception","(no exception)"))
|
|
print(" " + v.get("message",""))'
|
|
echo
|
|
echo "A different message, from a second check. The savepoint manager is obtained from the"
|
|
echo "object the JpaDialect returns when it begins the transaction, and Hibernate's does not"
|
|
echo "implement one -- so no amount of configuration gets NESTED working here."
|
|
echo
|
|
echo "== attempt 3: the same propagation on a JDBC transaction manager =="
|
|
echo "\$ curl -s localhost:$APP_PORT/tx/nested-jdbc"
|
|
echo
|
|
curl -s "http://127.0.0.1:${APP_PORT}/tx/nested-jdbc" | python3 -m json.tool | sed 's/^/ /'
|
|
echo
|
|
echo "This is what NESTED is for: the nested scope rolled back to its savepoint, the outer"
|
|
echo "transaction carried on and committed, and one of the two rows survived."
|
|
echo
|
|
echo "A savepoint is a JDBC concept. DataSourceTransactionManager holds the JDBC connection"
|
|
echo "and can issue one; JpaTransactionManager holds an EntityManager and cannot. The"
|
|
echo "reference documentation does say NESTED works with JDBC resource transactions -- what"
|
|
echo "it does not say is that the JPA path fails, twice, with two different messages."
|
|
stop_app
|
|
} > docs/output/03-nested.txt 2>&1
|
|
cat docs/output/03-nested.txt
|