1
0

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:
2026-09-08 16:36:32 +00:00
parent 879a06929a
commit 585eed4d57
53 changed files with 2278 additions and 68 deletions

View File

@@ -1,23 +1,26 @@
# sdjpa4-demo
Runnable companion project for the Spring Data JPA 3 to 4 migration series on ankurm.com:
Companion code for the Spring Data JPA and transaction articles on **[ankurm.com](https://ankurm.com)**.
- [Spring Data JPA 3 to 4 Migration Guide](https://ankurm.com/spring-data-jpa-3-to-4-migration-guide/) (overview, start here)
- [Migration Baseline](https://ankurm.com/spring-data-jpa-3-to-4-migration-guide-2/)
- [Query Engine Rewrite: Criteria to JPQL](https://ankurm.com/spring-data-jpa-4-derived-queries-criteria-to-jpql/)
- [Advanced Migration: Specifications, AOT, EntityManager](https://ankurm.com/spring-data-jpa-4-specifications-aot-entitymanager/)
Two independent Maven modules under one aggregator:
Four entities, three repositories, a `@NullMarked` package, 20 passing behavior tests, and an A-L demo runner that prints every labelled console output shown in the articles. Boots H2 in memory, so there's nothing to install beyond a JDK.
| Module | Article(s) | Boot / JDK |
|---|---|---|
| [`migration-behavior/`](migration-behavior) | the four Spring Data JPA 3&rarr;4 migration articles | 4.0.6 / 21 |
| [`transactions/`](transactions) | [@Transactional: propagation, isolation and the six silent failures](https://ankurm.com/) | 4.1.1 / 25 |
Built and verified on Eclipse Temurin JDK 21, Spring Boot 4.0.6, Spring Data JPA 4.0.6, Hibernate ORM 7.2, H2 in-memory.
The modules deliberately pin different Spring Boot versions. `migration-behavior` stays on
4.0.6 because that is what the four published migration articles were written and verified
against, and upgrading it would silently invalidate output those articles quote.
## Run it
> **Moved in September 2026.** The migration project used to live at the repository root. It is
> now under `migration-behavior/`; source paths gained that prefix and nothing else changed. The
> `article-1-baseline`, `article-2-query-engine` and `article-3-advanced` tags still point at the
> original layout, so a link into a tagged tree is unaffected.
```
git clone https://ankurm.com/git.app/asmhatre/sdjpa4-demo.git
cd sdjpa4-demo
./mvnw spring-boot:run # prints the labelled A-L demonstrations
./mvnw test # runs the 20 behavior tests (all green)
```bash
./mvnw -DskipTests package # both modules
./mvnw test # every test in both
```
## Tags