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:
36
transactions/scripts/demo-silent.sh
Executable file
36
transactions/scripts/demo-silent.sh
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
# The six ways @Transactional silently does nothing.
|
||||
set -euo pipefail
|
||||
set +m
|
||||
cd "$(dirname "$0")/.."
|
||||
source scripts/env.sh
|
||||
{
|
||||
echo "== six pieces of code carrying @Transactional that are not transactional =="
|
||||
echo
|
||||
echo "Row 0 is the control: the SAME annotated method, reached through the proxy."
|
||||
echo
|
||||
start_app > /dev/null
|
||||
curl -s "http://127.0.0.1:${APP_PORT}/tx/silent" | python3 -m json.tool | sed 's/^/ /'
|
||||
echo
|
||||
echo "Reading it:"
|
||||
echo
|
||||
echo " 0 control actualTransactionActive=true. The mechanism works."
|
||||
echo " 1 self-invocation entryPoint() is not annotated and calls this.annotated...(),"
|
||||
echo " so the proxy is never involved. Same class, same annotation,"
|
||||
echo " no transaction."
|
||||
echo " 2 private method a CGLIB proxy advises by overriding, and private methods"
|
||||
echo " cannot be overridden. Legal Java, no effect."
|
||||
echo " 3 checked exception the default rollback rule is RuntimeException or Error. A"
|
||||
echo " checked exception propagates AND the transaction commits."
|
||||
echo " Fix: @Transactional(rollbackFor = Exception.class)."
|
||||
echo " 4 swallowed nothing propagates, so the interceptor sees a normal return"
|
||||
echo " and commits. The write survives the failure it 'handled'."
|
||||
echo " 5 @PostConstruct the proxy does not exist yet during initialisation."
|
||||
echo " 6 new no container, no proxy, no transaction."
|
||||
echo
|
||||
echo "Note what rows 3 and 4 have in common: the row is still there afterwards. These two"
|
||||
echo "do not merely fail to start a transaction -- they start one and COMMIT work that the"
|
||||
echo "code was trying to abandon."
|
||||
stop_app
|
||||
} > docs/output/04-silent-failures.txt 2>&1
|
||||
cat docs/output/04-silent-failures.txt
|
||||
Reference in New Issue
Block a user