Install this skill
npx skills add giuseppe-trisciuoglio/developer-kitWorks across Claude Code, Cursor, Codex, Copilot & Antigravity
Spring Data JPA reduces boilerplate code when interacting with relational databases in Java applications. It abstracts standard data access layers by generating repository implementations at runtime from interfaces. Developers define data access patterns by extending standard repository abstractions, allowing the framework to resolve CRUD operations, pagination, and sorting dynamically. The system maps Java POJOs to database tables via persistence annotations while supporting complex relational mappings. It offers hooks for database auditing, transaction boundary management, and custom JPQL or SQL execution. By utilizing method name conventions, it minimizes the need for manual implementation of common lookup operations. This tool is intended for developers maintaining structured persistence layers where consistent entity management and predictable query execution are required across a service-oriented application architecture.
When to Use This Skill
- •Implementing standardized CRUD operations for domain entities
- •Managing one-to-many or many-to-many object-relational mappings
- •Retrieving large datasets through paginated API responses
- •Automating creation and modification timestamps for audit trails
How to Invoke This Skill
Example prompts that trigger this skill in Claude Code, Cursor, or Antigravity:
- “implement a repository for my entity
- “add pagination to my database queries
- “configure auditing on my JPA entities
- “how do I define a one-to-many relationship in JPA
- “write a custom JPQL query for my repository
Pro Tips
- 💡Leverage `Querydsl` for Complex Queries: While `@Query` and derived methods are powerful, consider integrating Querydsl for type-safe, dynamic, and complex query construction, especially in large applications with intricate search criteria.
- 💡Understand N+1 Problem: Be mindful of the N+1 select problem when defining relationships. Use `@EntityGraph` or `JOIN FETCH` clauses in your queries to eagerly fetch related entities and prevent excessive database roundtrips, significantly boosting performance.
- 💡Use DTOs for Read Operations: Avoid returning raw JPA entities directly from your service layer, especially for read-heavy operations. Map entities to Data Transfer Objects (DTOs) to decouple the domain model from the API, improve security, and tailor the data shape for consumers.
What this skill does
- •Automatic generation of repository implementations from interface declarations
- •Derived query method creation based on method naming conventions
- •Support for pagination and sorting using Pageable objects
- •Declarative auditing for entity lifecycle tracking
- •Integrated transaction management via @Transactional annotations
When not to use it
- ✕When working with non-relational or NoSQL data stores
- ✕When application performance requirements demand hyper-optimized raw SQL that JPA abstractions cannot produce
- ✕For extremely simple applications where a basic JDBC template is sufficient
Example workflow
- Define a domain model with @Entity and @Id annotations
- Create a repository interface extending JpaRepository
- Add derived query methods or @Query annotations for custom logic
- Configure an AuditingEntityListener to track date changes
- Inject the repository into a service layer class
- Use PageRequest objects to fetch data in chunks
Prerequisites
- –Java development environment
- –Spring Boot starter data JPA dependency
- –Configured DataSource (H2, MySQL, PostgreSQL, etc.)
Pitfalls & limitations
- !N+1 query problems occurring due to improper fetch strategies
- !Performance degradation caused by excessive EAGER loading of relationships
- !Overly long method names resulting from complex derived queries
- !Unexpected memory usage when fetching large result sets without pagination
FAQ
How it compares
Unlike manual JDBC or EntityManager implementation, Spring Data JPA eliminates repetitive boilerplate for standard CRUD operations and ensures query consistency through standardized method naming.
📄 Full skill instructions — original source: giuseppe-trisciuoglio/developer-kit
## Overview
To implement persistence layers with Spring Data JPA, create repository interfaces that provide automatic CRUD operations, entity relationships, query methods, and advanced features like pagination, auditing, and performance optimization.
## When to Use
Use this Skill when:
- Implementing repository interfaces with automatic CRUD operations
- Creating entities with relationships (one-to-one, one-to-many, many-to-many)
- Writing queries using derived method names or custom @Query annotations
- Setting up pagination and sorting for large datasets
- Implementing database auditing with timestamps and user tracking
- Configuring transactions and exception handling
- Using UUID as primary keys for distributed systems
- Optimizing performance with database indexes
- Setting up multiple database configurations
## Instructions
### Create Repository Interfaces
To implement a repository interface:
1. **Extend the appropriate repository interface:**
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
// Custom methods defined here
}2. **Use derived queries for simple conditions:**
Optional<User> findByEmail(String email);
List<User> findByStatusOrderByCreatedDateDesc(String status);3. **Implement custom queries with @Query:**
@Query("SELECT u FROM User u WHERE u.status = :status")
List<User> findActiveUsers(@Param("status") String status);### Configure Entities
1. **Define entities with proper annotations:**
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 100)
private String email;
}2. **Configure relationships using appropriate cascade types:**
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Order> orders = new ArrayList<>();3. **Set up database auditing:**
@CreatedDate
@Column(nullable = false, updatable = false)
private LocalDateTime createdDate;### Apply Query Patterns
1. **Use derived queries for simple conditions**
2. **Use @Query for complex queries**
3. **Return Optional<T> for single results**
4. **Use Pageable for pagination**
5. **Apply @Modifying for update/delete operations**
### Manage Transactions
1. **Mark read-only operations with @Transactional(readOnly = true)**
2. **Use explicit transaction boundaries for modifying operations**
3. **Specify rollback conditions when needed**
## Examples
### Basic CRUD Repository
@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
// Derived query
List<Product> findByCategory(String category);
// Custom query
@Query("SELECT p FROM Product p WHERE p.price > :minPrice")
List<Product> findExpensiveProducts(@Param("minPrice") BigDecimal minPrice);
}### Pagination Implementation
@Service
public class ProductService {
private final ProductRepository repository;
public Page<Product> getProducts(int page, int size) {
Pageable pageable = PageRequest.of(page, size, Sort.by("name").ascending());
return repository.findAll(pageable);
}
}### Entity with Auditing
@Entity
@EntityListeners(AuditingEntityListener.class)
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@CreatedDate
@Column(nullable = false, updatable = false)
private LocalDateTime createdDate;
@LastModifiedDate
private LocalDateTime lastModifiedDate;
@CreatedBy
@Column(nullable = false, updatable = false)
private String createdBy;
}## Best Practices
### Entity Design
- Use constructor injection exclusively (never field injection)
- Prefer immutable fields with
final modifiers- Use Java records (16+) or
@Value for DTOs- Always provide proper
@Id and @GeneratedValue annotations- Use explicit
@Table and @Column annotations### Repository Queries
- Use derived queries for simple conditions
- Use
@Query for complex queries to avoid long method names- Always use
@Param for query parameters- Return
Optional<T> for single results- Apply
@Transactional on modifying operations### Performance Optimization
- Use appropriate fetch strategies (LAZY vs EAGER)
- Implement pagination for large datasets
- Use database indexes for frequently queried fields
- Consider using
@EntityGraph to avoid N+1 query problems### Transaction Management
- Mark read-only operations with
@Transactional(readOnly = true)- Use explicit transaction boundaries
- Avoid long-running transactions
- Specify rollback conditions when needed
## Reference Documentation
For comprehensive examples, detailed patterns, and advanced configurations, see:
- [Examples](references/examples.md) - Complete code examples for common scenarios
- [Reference](references/reference.md) - Detailed patterns and advanced configurations
How to Use This Skill Unit
Option A: Project-Specific (Recommended)
- Click "Download" above
- In your project, create the directory:
.agent/skills/spring-data-jpa/ - Save the file as
SKILL.md - The agent will automatically discover the skill based on its description.
Option B: Global Installation (All Agents)
Save the file to these locations to make it available across all projects:
- Claude Code:
~/.claude/skills/giuseppe-trisciuoglio/developer-kit/spring-data-jpa/SKILL.md - Cursor:
~/.cursor/skills/giuseppe-trisciuoglio/developer-kit/spring-data-jpa/SKILL.md - Antigravity:
~/.gemini/antigravity/skills/giuseppe-trisciuoglio/developer-kit/spring-data-jpa/SKILL.md
🚀 Install with CLI:npx skills add giuseppe-trisciuoglio/developer-kit
