Agent skill · affaan-m
jpa-patterns
JPA/Hibernate patterns for entity design, relationships, query optimization, transactions, auditing, indexing, pagination, and pooling in Spring Boot. Use when designing JPA entities or relationships, or when a Hibernate query, transaction, or N+1 problem needs fixing.
What it needs
About 2k tokens when loaded.
What this skill does
JPA/Hibernate Patterns Use for data modeling, repositories, and performance tuning in Spring Boot. When to Activate Designing JPA entities and table mappings Defining relationships (@OneToMany, @ManyToOne, @ManyToMany) Optimizing queries (N+1 prevention, fetch strategies, projections) Configuring transactions, auditing, or soft deletes Setting up pagination, sorting, or custom repository methods Tuning connection pooling (HikariCP) or second-level caching Entity Design Enable auditing: Relationships and N+1 Prevention Default to lazy loading; use JOIN FETCH in queries when needed Avoid EAGER on collections; use DTO projections for read paths Repository Patterns Use projections for lightweight queries: Transactions Annotate service methods with @Transactional Use @Transactional(readOnly = true) for read paths to optimize Choose propagation carefully; avoid long-running transactions Pagination For cursor-like pagination, include id > :lastId in JPQL with ordering. Indexing and Performance Add indexes for common filters (status, slug, foreign keys) Use composite indexes matching query patterns (status, createdat) Avoid select ; project only needed columns Batch writes with saveAll and hibernate.jdbc.batchsize Connection Pooling (HikariCP) Recommended properties: For PostgreSQL LOB handling, add: Caching 1st-level cache is per EntityManager; avoid keeping entities across transactions For read-heavy entities, consider second-level cache cautiously; validate eviction strategy Migrations Use Flyway or Liquibase; never rely on Hibernate auto DDL in production Keep migrations idempotent and additive; avoid dropping columns without plan Testing Data Access Prefer @DataJpaTest with Testcontainers to mirror production Assert SQL efficiency using logs: set logging.level.org.hibernate.SQL=DEBUG and logging.level.org.hibernate.orm.jdbc.bind=TRACE for parameter values Remember: Keep entities lean, queries intentional, and transactions short. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills affaan-m/jpa-patterns--e1d320