Add the transactions module, and move the migration project under migration-behavior/
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
This commit is contained in:
43
transactions/scripts/demo-isolation.sh
Executable file
43
transactions/scripts/demo-isolation.sh
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
# Isolation and read-only: honoured where the transaction starts, ignored where it joins.
|
||||
set -euo pipefail
|
||||
set +m
|
||||
cd "$(dirname "$0")/.."
|
||||
source scripts/env.sh
|
||||
{
|
||||
echo "== isolation and readOnly =="
|
||||
echo
|
||||
start_app > /dev/null
|
||||
curl -s "http://127.0.0.1:${APP_PORT}/tx/isolation" | python3 -c '
|
||||
import json,sys
|
||||
d=json.load(sys.stdin)
|
||||
def show(label, s):
|
||||
print(" %-46s active=%-5s readOnly=%-5s isolation=%s" % (
|
||||
label, s["actualTransactionActive"], s["readOnly"], s["isolationLevel"]))
|
||||
show("@Transactional(readOnly = true)", d["readOnlyScope"])
|
||||
print()
|
||||
show("@Transactional(isolation = SERIALIZABLE) [outer]", d["serializableOuter"]["outer"])
|
||||
show(" REQUIRED inner joining it", d["serializableOuter"]["inner"])
|
||||
print()
|
||||
show("plain @Transactional [outer]", d["participantDeclaringReadUncommitted"]["outer"])
|
||||
show(" inner declaring READ_UNCOMMITTED", d["participantDeclaringReadUncommitted"]["inner"])'
|
||||
echo
|
||||
echo "The last pair is the point. The inner method declares"
|
||||
echo "@Transactional(isolation = READ_UNCOMMITTED) and gets ISOLATION_DEFAULT, because it"
|
||||
echo "joined an existing physical transaction whose isolation was fixed when it began."
|
||||
echo "The declaration is not rejected and nothing is logged -- it is simply ignored."
|
||||
echo
|
||||
echo "Set validateExistingTransaction=true on the transaction manager and this becomes an"
|
||||
echo "exception instead of a silent no-op. It is off by default."
|
||||
echo
|
||||
echo "The same applies to readOnly and timeout on a participating scope."
|
||||
echo
|
||||
echo "== the transaction manager's own log lines =="
|
||||
echo
|
||||
grep -E "Creating new transaction|Participating in existing" "$LOG" | tidy | head -12
|
||||
echo
|
||||
echo "Note ISOLATION_SERIALIZABLE appears on the 'Creating new transaction' line and never"
|
||||
echo "on a 'Participating' one: participation carries no settings of its own."
|
||||
stop_app
|
||||
} > docs/output/05-isolation.txt 2>&1
|
||||
cat docs/output/05-isolation.txt
|
||||
Reference in New Issue
Block a user