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:
37
transactions/docs/output/05-isolation.txt
Normal file
37
transactions/docs/output/05-isolation.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
== isolation and readOnly ==
|
||||
|
||||
@Transactional(readOnly = true) active=True readOnly=True isolation=default (from the connection)
|
||||
|
||||
@Transactional(isolation = SERIALIZABLE) [outer] active=True readOnly=False isolation=SERIALIZABLE
|
||||
REQUIRED inner joining it active=True readOnly=False isolation=SERIALIZABLE
|
||||
|
||||
plain @Transactional [outer] active=True readOnly=False isolation=default (from the connection)
|
||||
inner declaring READ_UNCOMMITTED active=True readOnly=False isolation=default (from the connection)
|
||||
|
||||
The last pair is the point. The inner method declares
|
||||
@Transactional(isolation = READ_UNCOMMITTED) and gets ISOLATION_DEFAULT, because it
|
||||
joined an existing physical transaction whose isolation was fixed when it began.
|
||||
The declaration is not rejected and nothing is logged -- it is simply ignored.
|
||||
|
||||
Set validateExistingTransaction=true on the transaction manager and this becomes an
|
||||
exception instead of a silent no-op. It is off by default.
|
||||
|
||||
The same applies to readOnly and timeout on a participating scope.
|
||||
|
||||
== the transaction manager's own log lines ==
|
||||
|
||||
o.s.orm.jpa.JpaTransactionManager: Creating new transaction with name [com.ankurm.tx.service.SilentlyNonTransactional.properlyCalled]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
|
||||
o.s.orm.jpa.JpaTransactionManager: Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.deleteAll]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
|
||||
o.s.orm.jpa.JpaTransactionManager: Creating new transaction with name [com.ankurm.tx.service.SilentlyNonTransactional.checkedExceptionCommits]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
|
||||
o.s.orm.jpa.JpaTransactionManager: Participating in existing transaction
|
||||
o.s.orm.jpa.JpaTransactionManager: Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.existsById]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
|
||||
o.s.orm.jpa.JpaTransactionManager: Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.existsById]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
|
||||
o.s.orm.jpa.JpaTransactionManager: Creating new transaction with name [com.ankurm.tx.service.SilentlyNonTransactional.swallowsException]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
|
||||
o.s.orm.jpa.JpaTransactionManager: Participating in existing transaction
|
||||
o.s.orm.jpa.JpaTransactionManager: Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.existsById]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
|
||||
o.s.orm.jpa.JpaTransactionManager: Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.existsById]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
|
||||
o.s.orm.jpa.JpaTransactionManager: Creating new transaction with name [com.ankurm.tx.service.OuterService.readOnlyScope]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
|
||||
o.s.orm.jpa.JpaTransactionManager: Participating in existing transaction
|
||||
|
||||
Note ISOLATION_SERIALIZABLE appears on the 'Creating new transaction' line and never
|
||||
on a 'Participating' one: participation carries no settings of its own.
|
||||
Reference in New Issue
Block a user