spring-data-jpa
Build data access layers with Spring Data JPA repository interfaces, entity relationships, and query patterns. Configure CRUD operations, derived and custom queries, pagination, database auditing, and transaction management. Includes best practices for performance optimization and entity design.
Spring Data JPA helps you implement persistence layers by providing repository patterns, entity configuration, and query strategies for database operations.
AI-generated summary based on this skill's SKILL.md
Install
giuseppe-trisciuoglio/developer-kit/spring-data-jpa · repository language: Python
git clone https://github.com/giuseppe-trisciuoglio/developer-kit
cp -r developer-kit/plugins/developer-kit-java/skills/spring-data-jpa ~/.claude/skills/spring-data-jpanpx skillfed install giuseppe-trisciuoglio/developer-kit/spring-data-jpaFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How do you create JPA repositories in Spring Data JPA?
spring-data-jpa repositories are created by extending the Repository interface or its subinterfaces like CrudRepository or JpaRepository. Define an interface with generic type parameters for your entity and ID type, then Spring Data JPA automatically generates CRUD operation implementations at runtime. You can add custom query methods using derived method names or @Query annotations without writing implementation code.
What are spring data jpa entity relationships and how do you configure them?
spring-data-jpa supports one-to-one, one-to-many, many-to-one, and many-to-many relationships using @OneToOne, @OneToMany, @ManyToOne, and @ManyToMany annotations. Configure cascade types to control how operations propagate (PERSIST, MERGE, REMOVE, REFRESH, DETACH, ALL), set fetch strategies (LAZY or EAGER), and use mappedBy to define the owning side of bidirectional relationships for proper database synchronization.
How does spring data jpa prevent N+1 query problems?
spring-data-jpa prevents N+1 problems using @EntityGraph annotations to specify which relationships to eagerly load in a single query, or by using JOIN FETCH in @Query methods. Define named entity graphs on your entity class with @NamedEntityGraph, then reference them in repository methods to control exactly which associations load together, avoiding cascading SELECT queries.
What pagination setup is needed with Spring Data JPA?
spring-data-jpa pagination is configured by adding a Pageable parameter to repository methods and returning Page<T> instead of List<T>. Spring automatically handles limit, offset, and sorting. Create Pageable instances using PageRequest.of(pageNumber, pageSize, Sort.by(...)) in your service layer, then pass to repository methods that support pagination for efficient large dataset handling.
How do you write efficient queries using @Query annotations in spring-data-jpa?
spring-data-jpa @Query annotations let you write custom JPQL or native SQL queries directly on repository methods. Use parameter binding with @Param, projections to fetch only needed columns, and JOIN FETCH for relationships. Combine with @Modifying for UPDATE/DELETE operations and @Transactional for write operations to optimize performance beyond derived query capabilities.
How is database auditing configured in Spring Data JPA?
spring-data-jpa enables auditing by adding @EnableJpaAuditing to your configuration class and annotating entity fields with @CreatedDate, @LastModifiedDate, @CreatedBy, and @LastModifiedBy. Implement AuditorAware<T> to provide current user information, then Spring automatically populates timestamps and user references on entity creation and modification without manual code.
SKILL.md
rendered from the published skill — quoted content, verbatim
Spring Data JPA
Overview
Provides patterns for Spring Data JPA repositories, entity relationships, queries, pagination, auditing, and transactions.
When to Use
Creating repositories with CRUD operations, entity relationships, @Query annotations, pagination, auditing, or UUID primary keys.
Instructions
Create Repository Interfaces
To implement a repository interface:
-
Extend the appropriate repository interface:
java @Repository public interface UserRepository extends JpaRepository<User, Long> { // Custom methods defined here } -
Use derived queries for simple conditions:
java Optional<User> findByEmail(String email); List<User> findByStatusOrderByCreatedDateDesc(String status); -
**Implement custom queries with
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 3 files
plugins/developer-kit-java/skills/spring-data-jpa/SKILL.md
plugins/developer-kit-java/skills/spring-data-jpa/references/examples.md
plugins/developer-kit-java/skills/spring-data-jpa/references/reference.md