jpa-patterns

Standardize Spring Boot data access with JPA/Hibernate entity and query patterns.

1|Updated Mar 20, 2024
One-click install
npx skills add https://github.com/flag3/dotfiles --skill jpa-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jpa-patterns
Source: https://github.com/flag3/dotfiles/tree/main/.claude/skills/jpa-patterns
Command: npx skills add https://github.com/flag3/dotfiles --skill jpa-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill standardizes Spring Boot data access by applying JPA/Hibernate patterns to build robust, maintainable, and high-performance persistence layers.

Core Features & Use Cases

  • Entity Design: define lean, well-indexed entities with auditing and default values.
  • Relationships & Performance: manage lazy loading, fetch joins, and N+1 prevention in queries.
  • Repositories & Transactions: establish clean repository patterns with transactional boundaries and projections.

Quick Start

Create a Spring Boot project and apply the provided JPA patterns to your Market, Position, and related entities to achieve efficient data access.

Frequently Asked Questions about jpa-patterns

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

FAQPage Schema
How do I prevent N+1 query problems in Spring Boot JPA repositories?

N+1 query problems occur when fetching an entity triggers separate queries for related data. Prevent this by using fetch joins in JPQL queries, explicit @EntityGraph annotations to define eager-load plans, or query projections to load only required fields. The Skill covers these strategies to optimize query execution and reduce database round trips.

What's the best way to design JPA entities for performance in Hibernate?

Design lean entities by excluding unnecessary fields, use proper indexing on frequently queried columns, apply lazy loading for relationships, and set sensible defaults. This Skill teaches entity design patterns that balance maintainability with query efficiency, including auditing fields and relationship configurations that avoid performance bottlenecks.

How do I implement pagination and transactional boundaries in Spring Boot repositories?

Use Spring Data's Pageable interface for offset-limit pagination, wrap repository methods with @Transactional to define query scope and isolation, and apply projections to return only needed columns. The Skill standardizes these patterns across repositories to ensure consistent, performant data access.

Can I use lazy loading and fetch joins together in JPA queries?

Fetch joins override lazy loading for specific queries, forcing immediate loading of related entities. Use them strategically in queries where you need related data to avoid N+1 problems, but rely on lazy loading as the default. The Skill covers when and how to apply each approach based on your access patterns.

What are the limitations of relying on Hibernate defaults for entity relationships?

Hibernate's default lazy loading and cascade settings can cause unexpected query bloat, detached-entity errors, and performance degradation if not explicitly configured. The Skill enforces explicit fetch plans and relationship boundaries to prevent these issues and make data access predictable.

How do I audit entity changes and track modification history in Spring Boot?

Use JPA auditing annotations (@CreatedDate, @LastModifiedDate, @CreatedBy) with Spring Data's @EnableJpaAuditing to automatically capture timestamps and user information. The Skill includes auditing patterns that standardize how entities record changes across your persistence layer.