Spring Data JPA

Standardizes entity, repository, query, and transaction design in Spring Data JPA.

Updated May 12, 2026
One-click install
npx skills add https://github.com/ZzZueszZ/claude-kit --skill spring-data-jpa-zzzueszz
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: Spring Data JPA
Source: https://github.com/ZzZueszZ/claude-kit/tree/main/.claude/skills/spring-data-jpa
Command: npx skills add https://github.com/ZzZueszZ/claude-kit --skill spring-data-jpa-zzzueszz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Designing the data layer in Spring Data JPA often leads to inconsistent entities, broken encapsulation from Lombok misuse, N+1 query problems, and misplaced transaction boundaries. This Skill provides a complete set of conventions and code templates to build a correct, maintainable JPA data layer. ## Core Features & Use Cases - Entity Design Standards: Enforces BaseEntity with audit fields, forbids @Data/@Setter on entities, and mandates domain methods plus correct equals()/hashCode() implementations. - Relationship & Query Patterns: Provides templates for bidirectional mappings with FetchType.LAZY, derived queries, JPQL, and N+1 solutions via JOIN FETCH, @EntityGraph, and @BatchSize. - Transaction, Soft Delete & Migration Rules: Defines @Transactional placement on services, soft delete with @Where filters, and Flyway migration naming conventions. - Use Case: When adding a new Order entity with items to a Spring Boot project, use this Skill to generate the entity, repository, and service layer following all encapsulation and lazy-loading rules, then verify with the pre-commit checklist. ## Quick Start Ask the AI to create a new JPA entity with its repository and service following the Spring Data JPA skill conventions.

Frequently Asked Questions about Spring Data JPA

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

FAQPage Schema
How do I design JPA entities without Lombok @Data?▼

Use only @Getter with @Builder and a protected @NoArgsConstructor on JPA entities, and change state through domain methods like activate() or updateProfile(). @Data generates setters, toString, and equals implementations that break encapsulation and cause issues with lazy-loaded relationships.

How to fix N+1 query problem in Spring Data JPA?▼

Use JOIN FETCH in a JPQL query for the most common access path, @EntityGraph for reusable fetch strategies, or @BatchSize when JOIN FETCH is not possible. Always verify by enabling spring.jpa.show-sql in development to inspect generated queries.

Should @Transactional be on the service or repository layer?▼

Place @Transactional on the service layer, never on controllers or repositories. Use class-level @Transactional(readOnly = true) as the default and override with @Transactional on write methods, specifying rollbackFor for checked exceptions.

Why avoid GenerationType.AUTO for JPA primary keys?▼

GenerationType.AUTO behaves differently across databases, sometimes selecting sequence-based strategies that break batch inserts. Use GenerationType.IDENTITY for auto-increment columns to get consistent, predictable behavior.

How do I implement soft delete in Spring Data JPA?▼

Create a SoftDeletableEntity mapped superclass with deleted and deletedAt fields plus a softDelete() method, then add Hibernate's @Where(clause = "deleted = false") on the entity so repositories automatically filter out deleted rows.

When is it acceptable to use @Setter in a Spring project?▼

@Setter is acceptable on @ConfigurationProperties classes because Spring binding requires it, and on DTOs or request/response objects where @Data or records are fine. JPA entities should never expose setters.