jpa-patterns_skill

This skill helps you design JPA entities, optimize queries, and configure transactions in Spring Boot for reliable, scalable data access.
  • JavaScript

46.5k

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill affaan-m/everything-claude-code --skill jpa-patterns

  • SKILL.md4.4 KB

Overview

This skill codifies battle-tested JPA/Hibernate patterns for Spring Boot applications, covering entity design, relationships, query optimization, transactions, auditing, indexing, pagination, and connection pooling. It focuses on practical, production-ready guidance to build efficient, maintainable data layers and avoid common pitfalls like N+1 queries and incorrect transaction scopes.

How this skill works

The skill inspects typical data-access concerns and prescribes concrete patterns: annotated entity examples, relationship mappings, repository query styles, and configuration snippets for auditing and HikariCP. It highlights when to use fetch joins, DTO projections, pagination strategies, batching, and second-level caching while advising migration and testing practices. Each recommendation maps to simple code fragments or configuration properties you can apply directly in a Spring Boot project.

When to use it

  • Designing JPA entities and table mappings with indexes and auditing
  • Defining and tuning relationships (OneToMany, ManyToOne, ManyToMany) to prevent N+1
  • Optimizing read paths with projections, JOIN FETCH, and pagination
  • Configuring transactions, propagation, and read-only boundaries
  • Tuning connection pooling (HikariCP), batching, and second-level cache usage
  • Setting up migrations and integration tests with Testcontainers

Best practices

  • Default collections to LAZY and avoid EAGER on collections; use JOIN FETCH for specific queries
  • Prefer DTO projections or interface projections for read-heavy endpoints to reduce selected columns
  • Annotate service methods with @Transactional; use readOnly=true for queries and keep transactions short
  • Add indexes for common filters and composite indexes that match query patterns
  • Batch writes with saveAll and set hibernate.jdbc.batch_size; monitor SQL via Hibernate logs during testing
  • Use Flyway/Liquibase for migrations; avoid Hibernate auto-DDL in production

Example use cases

  • Fetch a Market with its Positions using a JOIN FETCH query to prevent N+1
  • Expose a lightweight MarketSummary projection for paginated dashboards
  • Implement soft deletes and auditing with @CreatedDate/@LastModifiedDate and @EnableJpaAuditing
  • Configure HikariCP properties for stable connection pooling in production
  • Write integration data tests with @DataJpaTest plus Testcontainers to validate SQL and migrations

FAQ

Keep collections LAZY and use explicit JOIN FETCH queries or projections for read paths that need related entities.

When should I enable second-level cache?

Consider second-level caching only for stable, read-heavy entities; validate eviction strategy and measure before enabling in production.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
jpa-patterns skill by affaan-m/everything-claude-code | VeilStrat