jpa-patterns

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

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill jpa-patterns-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: jpa-patterns
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/jpa-patterns
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill jpa-patterns-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Designing efficient data access layers in Spring Boot is error-prone: N+1 query problems, misconfigured relationships, missing indexes, and long-running transactions degrade performance and reliability. This Skill provides proven JPA/Hibernate patterns to model entities, optimize queries, and manage transactions correctly. ## Core Features & Use Cases - Entity Design & Auditing: Define entities with proper table mappings, unique constraints, enum handling, and automatic created/updated timestamps via @EnableJpaAuditing. - Query Optimization: Prevent N+1 issues with JOIN FETCH, lazy loading defaults, and DTO projections for lightweight read paths. - Transactions, Pagination & Pooling: Apply @Transactional best practices, offset and cursor-style pagination, composite indexing, and HikariCP connection pool tuning. - Use Case: When building a Spring Boot service backed by MySQL or PostgreSQL, use this Skill to scaffold repositories with paginated queries, fetch strategies, and Flyway-managed migrations instead of relying on Hibernate auto DDL. ## Quick Start Ask the AI to design a JPA entity with relationships, an optimized repository with pagination, and transactional service methods 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. Avoid EAGER fetching on collections and use DTO projections for read-only paths to load only required columns.

How to implement pagination with Spring Data JPA?▼

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

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, set hibernate.jdbc.lob.non_contextual_creation to 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.