Implements the Stable and Experimental JPA persistence platform designs against real PostgreSQL, adapted to this repository's fail-closed 19-leaf registry. The design models the platform as 25 Gradle projects. `src/settings.gradle` throws unless the registry holds exactly 19 leaves, so the plan's modules become packages inside `:adapter:outbound:persistence-jpa` (starter in `:app-bootstrap`, testkit in its own source set). The full mapping, the renames this repository's naming gate required, and every deliberate substitution are recorded in `docs/jpa/repository-adaptation.md`. Seven Docker-backed lanes replace the plan's seven JVM test suites. Each fails closed: a lane that discovers nothing, or a container that cannot start, is an error rather than a skip. Three defects the contracts found against a real server: - `CommitFailureClassifier` treated only SQLSTATE 40003, class 08, and transport breaks as completion-unknown. A backend terminated mid-commit reports 57P01, and the commit record may already be in the WAL — so a possibly-committed transaction could be re-run. 57P01/57P02/57P03 now classify as completion-unknown. - `SchemaTenantMigrationOrchestrator` recorded `MigrateResult`'s target version, which is empty for a tenant already current, reporting migrated tenants as unmigrated during a partial rollout. It now reads the applied version back from the tenant's schema history. - `JpaStreamExecutor` checked only the declared return type for reactive publishers, and `RegisteredPostgreSqlCopyLoader` passed the COPY timeout to `SET`, which is parsed before parameter binding. `JpaModuleBoundaryTest` enforces the plan's module map as package rules; `verifyCleanArchitectureDependencies` governs edges between leaves and cannot see these. Its first assertion is that the import is non-empty, because every rule under it is a `noClasses()` rule and would pass vacuously on an empty import. Verified: 128 container tests across all seven lanes, 1183 unit tests, `:adapter:outbound:persistence-jpa:check`, `:app-bootstrap:check`, `verifyCleanArchitectureDependencies`, `verifyOneTypePerFile`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
38 lines
1.6 KiB
Markdown
38 lines
1.6 KiB
Markdown
# ADR-JPA-002 — Retry re-runs the whole use case
|
|
|
|
- Status: Accepted
|
|
- Date: 2026-08-11
|
|
- Design: §19.2
|
|
|
|
## Context
|
|
|
|
Optimistic conflicts, deadlocks, and serialization failures are recoverable. The question is what
|
|
unit gets retried: the failed statement, the transaction, or the use case.
|
|
|
|
## Decision
|
|
|
|
The whole use case, in a new transaction with a new Persistence Context.
|
|
`FullTransactionRetryCoordinator` re-enters `JpaTransactionExecutor` for every attempt, and the
|
|
retry advice is ordered outside Spring's transaction advice so each attempt begins a new
|
|
transaction.
|
|
|
|
## Consequences
|
|
|
|
Statement-level retry is wrong for exactly the failures being retried. An optimistic conflict means
|
|
the state the attempt computed against is no longer the committed state; re-issuing the same
|
|
statement computes the same wrong answer against a version that has moved on. The domain rules have
|
|
to run again over reloaded data, which means the whole use case.
|
|
|
|
Reusing the Persistence Context would be equally wrong: the second attempt would read the first
|
|
attempt's stale entities out of the first-level cache. And with the advice ordering inverted, the
|
|
retry loop would run inside one transaction that has already been marked rollback-only, so the
|
|
second attempt fails immediately without executing anything.
|
|
|
|
The cost is that a retryable use case must be safe to run from scratch — no irreversible external
|
|
effect before the commit. `IrreversibleSideEffectContext` lets a use case declare when that does not
|
|
hold, and the policy then refuses to retry it whatever budget remains.
|
|
|
|
## Enforcement
|
|
|
|
`FullTransactionRetryCoordinatorTest`; `RetryableJpaTransactionInterceptor.DEFAULT_ORDER`.
|