jpa-patterns

Implements JPA/Hibernate entity design, query optimization, and transaction patterns in Spring Boot.

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill jpa-patterns-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jpa-patterns
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/jpa-patterns
Command: npx skills add https://github.com/ibytechaos/claude --skill jpa-patterns-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Spring Boot developers frequently encounter N+1 query problems, poorly indexed tables, misconfigured transactions, and inefficient pagination when building JPA/Hibernate data layers, leading to slow applications and production incidents. ## Core Features & Use Cases - Entity & Relationship Design: Provides annotated entity templates with auditing (@CreatedDate, @LastModifiedDate), proper @OneToMany mappings, and index definitions. - Query Optimization: Prevents N+1 issues with JOIN FETCH queries, DTO projections, and lazy-loading strategies for read paths. - Transactions, Pagination & Pooling: Covers @Transactional best practices, Pageable-based pagination, HikariCP tuning, and Flyway/Liquibase migration guidance. - Use Case: When building a Spring Boot service with a Market entity that has child positions, apply these patterns to define the mapping, fetch positions without N+1 queries, paginate results by status, and configure the connection pool. ## Quick Start Ask the AI to design a JPA entity with relationships and an optimized repository for your Spring Boot domain model using these patterns.

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 queries in JPA Hibernate?

Prevent N+1 queries by defaulting to lazy loading and using JOIN FETCH in JPQL queries when related entities are needed. For read-only paths, use DTO projections instead of fetching full entity graphs, and avoid EAGER fetching on collections.

How to add pagination to a Spring Data JPA repository?

Add a Pageable parameter to your repository method and return a Page type, for example Page<MarketEntity> findByStatus(MarketStatus status, Pageable pageable). Build the pageable with PageRequest.of(page, size, Sort.by("createdAt").descending()).

Should I use Hibernate auto DDL in production?

No, never rely on Hibernate auto DDL in production. Use Flyway or Liquibase for schema migrations, keeping them idempotent and additive, and avoid dropping columns without a migration plan.

What HikariCP settings are recommended for Spring Boot?

Recommended HikariCP settings include maximum-pool-size of 20, minimum-idle of 5, connection-timeout of 30000ms, and validation-timeout of 5000ms. For PostgreSQL LOB handling, also set hibernate.jdbc.lob.non_contextual_creation to true.

How do I test JPA repositories with a real database?

Use @DataJpaTest combined with Testcontainers to run tests against a database matching production. Enable SQL logging with logging.level.org.hibernate.SQL=DEBUG and bind parameter tracing to assert query efficiency.