Files
clean-architecture-backend-…/docs/adr/ADR-JPA-001-domain-owns-persistence-model.md
T
DongHyeonkaandClaude Opus 5 0e61f86eb5 feat(jpa): implement the JPA relational persistence platform
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>
2026-08-14 14:06:18 +09:00

1.5 KiB

ADR-JPA-001 — The domain owns the persistence model

  • Status: Accepted
  • Date: 2026-08-11
  • Design: §10.1, §23.3

Context

A persistence platform can either own the repository abstraction — a GenericRepository<T, ID> every aggregate inherits — or provide only the pieces domains assemble themselves.

Decision

The domain owns entities, embeddables, repositories, queries, index requirements, and lock, soft-delete, and audit policy. The platform provides no generic CRUD repository and no base repository. JpaRepositoryFragmentSupport exists, has no save, findById, findAll, or delete, and is enforced not to acquire them.

Consequences

A generic base repository has one property that looks like a benefit and is not: every aggregate gets the same operations. That means each aggregate is offered operations that may be wrong for it — a delete on an append-only ledger, a findAll on a table that will never be small — and, worse, one aggregate's later requirement changes the shared base and therefore changes behaviour for aggregates nobody reviewed.

Spring Data already implements CRUD. Re-implementing it adds a layer whose only function is to be harder to opt out of.

The cost is a small amount of repetition: each domain declares the repository interface it needs. That repetition is the thing that makes each aggregate's persistence surface reviewable.

Enforcement

JpaArchitectureRules.noGenericRepository(); JpaRepositoryFragmentSupportTest.