jpa-patterns

Guide JPA and Hibernate patterns for performance and common pitfalls.

70|22|Updated Jun 10, 2020
One-click install
npx skills add https://github.com/piomin/spring-boot-istio --skill jpa-patterns-piomin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jpa-patterns
Source: https://github.com/piomin/spring-boot-istio/tree/main/.claude/skills/jpa-patterns
Command: npx skills add https://github.com/piomin/spring-boot-istio --skill jpa-patterns-piomin

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers overcome common performance bottlenecks and pitfalls in Java Persistence API (JPA) and Hibernate, such as the N+1 query problem and LazyInitializationException.

Core Features & Use Cases

  • N+1 Problem Detection & Solutions: Identifies and provides fixes for excessive SQL queries.
  • Lazy Loading Optimization: Guides on correctly handling lazy loading to prevent LazyInitializationException.
  • Transaction Management: Explains best practices for @Transactional and propagation.
  • Query Optimization: Covers pagination, DTO projections, and bulk operations.
  • Use Case: When encountering "Too many SQL queries executing" or LazyInitializationException errors, this Skill offers immediate solutions like using JOIN FETCH or @EntityGraph.

Quick Start

Use the jpa-patterns skill to help me fix the N+1 problem in my Spring Data JPA application.

Frequently Asked Questions about jpa-patterns

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

FAQPage Schema
How do I fix the N+1 query problem in Spring Data JPA?

Resolve the N+1 query problem in Spring Data JPA by applying JOIN FETCH, @EntityGraph, or @BatchSize to optimize lazy loading and reduce excessive SQL queries.

What is the best way to handle LazyInitializationException in Hibernate?

Handle LazyInitializationException in Hibernate by properly configuring transaction management boundaries or using JOIN FETCH to initialize associations before the session closes.

How does @Transactional propagation work for JPA query optimization?

@Transactional propagation works for JPA query optimization by defining transaction boundaries that keep Hibernate sessions open, preventing lazy loading exceptions and managing data consistency.

When should I use DTO projections instead of entity fetching in JPA?

Use DTO projections instead of entity fetching in JPA when you need read-only data without the overhead of full entity hydration, significantly improving query performance and reducing memory usage.

Can I use @EntityGraph with Spring Data JPA for pagination?

Yes, you can use @EntityGraph with Spring Data JPA for pagination to eagerly fetch required associations while maintaining paginated results, avoiding LazyInitializationException without loading entire datasets.