persistence

Configures Spring Boot persistence layers with JPA repositories, Flyway migrations, and transaction boundaries.

Updated Jun 25, 2026
One-click install
npx skills add https://github.com/oriddd/ai-toolkit --skill persistence-oriddd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: persistence
Source: https://github.com/oriddd/ai-toolkit/tree/main/copilot/public/skills/persistence
Command: npx skills add https://github.com/oriddd/ai-toolkit --skill persistence-oriddd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up a correct persistence layer in a Spring Boot service involves many subtle decisions — entity design, ID generation, locking, migrations, and transaction placement — that are easy to get wrong and expensive to fix later. This Skill encodes the proven conventions so every new service or aggregate follows the same durable-storage patterns. ## Core Features & Use Cases - Entity & Repository Conventions: Enforces application-assigned UUIDs, @Version optimistic locking, string-based enums, JPA auditing, and lazy fetching across all JPA entities. - Flyway Migration Discipline: Forward-only migrations, no Hibernate auto-DDL, strict naming, and Testcontainer-based migration tests on every commit. - Transaction & Query Patterns: Service-layer @Transactional boundaries, read-only hints, and the Specification pattern for composable queries instead of exploding derived-method names. - Use Case: When adding a new aggregate to an existing service, apply this Skill to generate the entity, repository, Flyway migration, and audited base classes following the standard layout. ## Quick Start Apply the persistence skill to scaffold the entity, repository, and Flyway migration for a new Document aggregate in this Spring Boot service.

Frequently Asked Questions about persistence

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

FAQPage Schema
How do I set up Spring Data JPA repositories in Spring Boot?

Create an interface extending JpaRepository and JpaSpecificationExecutor for each aggregate, placed under a repository package. Business code depends only on these interfaces, never on the EntityManager, and all list queries must use a Pageable.

How to manage database migrations with Flyway in Spring Boot?

Write forward-only SQL migrations named V001__init.sql, V002__add_status.sql under db/migration, and never edit a checked-in migration. Set spring.jpa.hibernate.ddl-auto to validate so Flyway owns the schema, and add a Testcontainer test that runs all migrations on every commit.

Should JPA entities use database sequences or UUIDs for IDs?

Use application-assigned IDs such as UUID v7 or ULID rather than database sequences or auto-increment. This makes inserts non-blocking and keeps IDs stable across environments.

Where should @Transactional be placed in a Spring Boot service?

Place @Transactional on service-layer methods, never on controllers or repositories. Mark read operations with readOnly = true, and never call a transactional method from another method of the same class because Spring proxying will not intercept it.

How do I avoid N+1 queries and eager loading in JPA?

Always use FetchType.LAZY and fetch what you need with a Specification or EntityGraph. Detect N+1 problems with the Hibernate SQL logger in tests or the datasource-proxy spy in integration tests.

What are the options for multi-tenancy in a Spring Boot application?

Choose between a shared-schema discriminator column with Hibernate @Filter, a separate schema per tenant with a MultiTenantConnectionProvider, or a separate database per tenant. Start with the discriminator column unless strict regulatory isolation is required.