persistence-conventions

Defines JPA persistence conventions for a DDD hexagonal Spring Boot backend.

Updated Aug 10, 2026
One-click install
npx skills add https://github.com/LeeHyunWoo02/ProvinceHow --skill persistence-conventions-leehyunwoo02
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: persistence-conventions
Source: https://github.com/LeeHyunWoo02/ProvinceHow/tree/main/.claude/skills/persistence-conventions
Command: npx skills add https://github.com/LeeHyunWoo02/ProvinceHow --skill persistence-conventions-leehyunwoo02

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? In a DDD hexagonal architecture, mixing domain models with JPA entities, misusing transactions across dual DataSources, and mishandling schema evolution cause subtle, late-discovered bugs. This Skill codifies the persistence rules of the ProvinceHow (smash) backend so entities, repositories, transactions, and batch writers are written consistently and safely. ## Core Features & Use Cases - Domain/JPA Separation: Enforces separate domain models, JpaEntity classes, hand-written Mappers, and Repository port/adapter layers, with cross-Aggregate references stored as code columns instead of object relations. - Dual DataSource Transaction Safety: Mandates explicit transactionManager = "dataTransactionManager" on application-layer @Transactional annotations so operations never silently bind to the wrong transaction manager. - Batch Upsert & Schema Rules: Standardizes JdbcBatchItemWriter with ON DUPLICATE KEY UPDATE, Processor-side value-object validation, and documents the limits of hbm2ddl.auto=update including the RENAME INDEX workaround for legacy FK indexes. - Use Case: When adding a new JPA entity, repository query, JPQL projection, or Spring Batch writer to the smash backend, apply these conventions to keep the hexagonal boundaries and MySQL schema consistent. ## Quick Start Ask the AI to create a new JPA entity and repository adapter for a domain concept following the persistence-conventions rules.

Frequently Asked Questions about persistence-conventions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I separate domain models from JPA entities in a hexagonal architecture?

Keep the domain model free of JPA annotations and create a separate JpaEntity class in infrastructure/persistence, with a hand-written Mapper converting between them. The domain model uses value objects like SigunguCode while the entity stores primitive types.

How should JPA entities reference other Aggregates in DDD?

Reference other Aggregates by a plain code column such as sigunguCode instead of a @ManyToOne object relation. This eliminates lazy loading and N+1 problems and enforces context boundaries at compile time; joins are written explicitly in JPQL projections.

Why must @Transactional specify the transactionManager name with multiple DataSources?

With two DataSources, an unqualified @Transactional binds to whichever manager is marked @Primary, which can silently change. Always declare transactionManager = "dataTransactionManager" so JPA operations use the correct persistence context.

Does hbm2ddl.auto=update handle column deletion or type changes?

No, the update strategy only applies additive changes like new columns, tables, and indexes. Column deletion, type narrowing, or constraint removal requires a manual DDL script stored under docker/mysql/ddl and shared with the team.

How do I write an idempotent Spring Batch upsert writer for MySQL?

Use JdbcBatchItemWriter with an INSERT ... ON DUPLICATE KEY UPDATE statement, inject the DataSource with @Qualifier("dataDBSource"), and ensure the target table has a unique constraint. Validate domain invariants in the Processor by constructing value objects and returning null to skip invalid items.