jpa-patterns

Implements JPA and Hibernate patterns for entity design, queries, and transactions in Spring Boot.

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill jpa-patterns-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jpa-patterns
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/jpa-patterns
Command: npx skills add https://github.com/Femad-6/my-skills --skill jpa-patterns-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Designing JPA entities, relationships, and queries in Spring Boot often leads to N+1 query problems, inefficient transactions, and missing indexes that degrade application performance. ## Core Features & Use Cases - Entity and Relationship Design: Provides annotated entity templates with auditing, indexes, and lazy-loaded @OneToMany/@ManyToOne mappings. - Query Optimization: Covers N+1 prevention with JOIN FETCH, DTO projections, pagination with Pageable, and composite indexing strategies. - Transactions and Infrastructure: Guides @Transactional usage, HikariCP pool tuning, Flyway migrations, and @DataJpaTest testing with Testcontainers. - Use Case: When building a Spring Boot service with a Market entity that has child positions, apply these patterns to fetch related data in one query, paginate results, and tune the connection pool. ## Quick Start Ask the assistant to design a JPA entity with relationships and an optimized repository for your Spring Boot domain model.

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 and Hibernate?

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

How to implement pagination in Spring Data JPA?

Use PageRequest.of(page, size, Sort) with repository methods returning Page<T>. For cursor-like pagination, add an id > :lastId condition in JPQL with explicit ordering to avoid offset-based performance issues.

Should I use Hibernate auto DDL or Flyway for database migrations?

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

What HikariCP settings should I use in Spring Boot?

Set maximum-pool-size to 20, minimum-idle to 5, connection-timeout to 30000, and validation-timeout to 5000 as a baseline. For PostgreSQL LOB handling, add hibernate.jdbc.lob.non_contextual_creation=true.

How do I test JPA repositories in Spring Boot?

Use @DataJpaTest with Testcontainers to mirror the production database. Enable SQL logging with logging.level.org.hibernate.SQL=DEBUG and bind parameter tracing to assert query efficiency.