spring-data-jpa

Implement Spring Data JPA persistence layers with repositories, entities, and queries.

322|37|Updated Oct 21, 2025
One-click install
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill spring-data-jpa
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spring-data-jpa
Source: https://github.com/giuseppe-trisciuoglio/developer-kit/tree/main/skills/spring-boot/spring-data-jpa
Command: npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill spring-data-jpa

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides concrete patterns for Spring Data JPA, including repositories, entities, derived queries, @Query usage, pagination, auditing, and performance considerations.

Core Features & Use Cases

  • Repository interfaces with derived queries and @Query
  • Entity relationships, auditing, and transactions
  • Pagination and performance optimization patterns
  • Multi-database and indexing considerations

Quick Start

Define an entity with a repository, and implement a paged query to fetch data with sorting.

Frequently Asked Questions about spring-data-jpa

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

FAQPage Schema
How do I set up pagination and sorting with Spring Data JPA repositories?

Spring Data JPA pagination is implemented by returning `Page<T>` from repository methods that accept a `Pageable` parameter. Pass `PageRequest.of(pageNumber, pageSize, Sort.by(field))` to retrieve sorted, paginated results with metadata like total count and available pages.

What's the difference between derived queries and @Query annotations in Spring Data JPA?

Derived queries use method naming conventions (e.g., `findByEmail`) for simple lookups; @Query lets you write JPQL or SQL for complex filtering, joins, and aggregations. Use derived queries for straightforward cases and @Query when the logic exceeds naming conventions.

How do I implement auditing to track entity changes in Spring Data JPA?

Spring Data JPA auditing automatically manages creation and modification timestamps and user information. Enable it with `@EnableJpaAuditing`, annotate entity fields with `@CreatedDate`, `@LastModifiedDate`, and provide an `AuditorAware` bean to capture the current user.

Can I use UUID primary keys with Spring Data JPA instead of auto-increment IDs?

Yes, UUID primary keys work with Spring Data JPA. Annotate the field with `@Id` and `@GeneratedValue(strategy = GenerationType.UUID)`, or generate and assign UUIDs in code before persistence. This avoids sequential ID exposure and scales across distributed databases.

How do I configure multiple databases with Spring Data JPA repositories?

Configure multiple `DataSource` beans, create separate `EntityManagerFactory` and `TransactionManager` for each database, and partition repositories by package. Use `@EnableJpaRepositories` with `basePackages` to route each repository package to its corresponding persistence unit.

What indexing strategies improve query performance in Spring Data JPA?

Add `@Index` annotations on frequently queried entity fields, create composite indexes for multi-column WHERE and JOIN predicates, and index foreign keys. Combine with derived query method names and @Query optimization to reduce full table scans and accelerate pagination.