spring-data-jpa

Implements Spring Data JPA persistence layers with repositories, queries, and transactions.

Updated Jun 28, 2026
One-click install
npx skills add https://github.com/412181-HerediaLara/ScaffoldingBE-FE --skill spring-data-jpa-412181-heredialara
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: spring-data-jpa
Source: https://github.com/412181-HerediaLara/ScaffoldingBE-FE/tree/main/BE/.agents/skills/spring-data-jpa
Command: npx skills add https://github.com/412181-HerediaLara/ScaffoldingBE-FE --skill spring-data-jpa-412181-heredialara

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building a correct and performant persistence layer in Spring Boot requires many decisions: repository design, entity relationships, query strategies, pagination, auditing, and transaction boundaries. This Skill provides proven patterns and reference implementations so you avoid common pitfalls like N+1 queries, incorrect cascade behavior, and missing indexes. ## Core Features & Use Cases - Repository & Query Patterns: Create JpaRepository interfaces with derived queries, custom @Query (JPQL and native), @Modifying updates, and pagination with Pageable. - Entity Modeling: Configure one-to-one, one-to-many, and many-to-many relationships, UUID primary keys, database indexes, and auditing with @CreatedDate/@LastModifiedDate. - Transaction & Performance Guidance: Apply @Transactional boundaries, propagation levels, @EntityGraph to prevent N+1 queries, and batch operations. - Use Case: When building a Spring Boot backend that must persist game or business entities with 95% test coverage, use this Skill to scaffold repositories, relationships, and paginated queries correctly the first time. ## Quick Start Ask the AI to create a Spring Data JPA repository with pagination and auditing for your entity, for example: "Create a Product entity with a category relationship, a repository with derived and custom queries, and a paginated service method."

Frequently Asked Questions about spring-data-jpa

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

FAQPage Schema
How do I create a Spring Data JPA repository with custom queries?▼

Extend JpaRepository with your entity and ID type, then add derived query methods like findByEmail or annotate methods with @Query for JPQL or native SQL. Use @Param to bind method parameters to named query parameters.

How to avoid N+1 query problems in Spring Data JPA?▼

Use @EntityGraph with attributePaths on repository methods or JOIN FETCH in JPQL queries to load associations in a single query. Avoid EAGER fetch on collections, which causes excessive database round trips.

Does Spring Data JPA support UUID primary keys?▼

Yes, annotate the ID field with @GeneratedValue(strategy = GenerationType.UUID) and use UUID as the repository ID type. Be aware that random UUIDs can cause index fragmentation, so consider sequential UUIDs or Long IDs for high-volume tables.

How do I add auditing fields like createdDate in JPA entities?▼

Enable auditing with @EnableJpaAuditing, add @EntityListeners(AuditingEntityListener.class) to the entity, and annotate fields with @CreatedDate, @LastModifiedDate, @CreatedBy, and @LastModifiedBy. Provide an AuditorAware bean to supply the current user.

When should I use @Transactional readOnly in Spring services?▼

Apply @Transactional(readOnly = true) to query-only service methods to enable flush-mode optimizations and hint the database for read replicas. Use explicit transaction boundaries with rollback rules for modifying operations.

Why does CascadeType.REMOVE cause performance issues in JPA?▼

Cascading removes on large collections triggers individual delete statements per child entity, which is slow and can lock tables. Prefer orphanRemoval with controlled collection sizes or bulk @Modifying delete queries for large datasets.