jpa-patterns
Master JPA entity modeling, repository implementation, and performance tuning for Spring Boot applications. Learn to configure relationships, prevent N+1 query issues through fetch strategies and projections, set up transactional boundaries, and optimize database connections with HikariCP.
jpa-patterns helps you design JPA entities with relationships and optimize queries to prevent N+1 problems in Spring Boot.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-03-05
jpa-patterns helps you design JPA entities with relationships and optimize queries to prevent N+1 problems in Spring Boot. Master JPA entity modeling, repository implementation, and performance tuning for Spring Boot applications. Learn to configure relationships, prevent N+1 query issues through fetch strategies and projections, set up transactional boundaries, and optimize database connections with HikariCP.
Use it when
- jpa-patterns covers OneToMany, ManyToOne, ManyToMany, and OneToOne relationships with practical entity design patterns.
- jpa-patterns teaches Spring Boot transaction management using @Transactional with proper propagation and isolation levels.
Verify before relying
Read SKILL.md below before installing (1 file). Open directory: indexed for reading, not audited.
Install
xu-xiang/everything-claude-code-zh/jpa-patterns · repository language: JavaScript
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How does jpa-patterns help prevent N+1 query problems?
jpa-patterns teaches you to identify and eliminate N+1 query issues through strategic fetch strategies and projections. The skill covers lazy vs. eager loading trade-offs, using @Query with JOIN FETCH to load related entities in a single query, and implementing DTO projections to fetch only needed columns. You'll learn when to apply each technique based on your access patterns.
What entity design and JPA relationships does jpa-patterns cover?
jpa-patterns covers OneToMany, ManyToOne, ManyToMany, and OneToOne relationships with practical entity design patterns. You'll learn how to model bidirectional vs. unidirectional relationships, configure cascade types appropriately, and use @JoinColumn and @JoinTable annotations correctly. The skill emphasizes designing relationships that support efficient queries and prevent common pitfalls.
How do I configure transaction management and auditing in jpa-patterns?
jpa-patterns teaches Spring Boot transaction management using @Transactional with proper propagation and isolation levels. For auditing, you'll learn to use @CreatedDate, @LastModifiedDate, and @EntityListeners to automatically track entity changes. The skill covers setting up AuditorAware beans to capture user information and configuring audit tables for compliance.
What Hibernate performance tuning techniques are included?
jpa-patterns covers Hibernate performance optimization including connection pooling with HikariCP, composite index design for query acceleration, and second-level caching strategies. You'll learn batch insert operations with saveAll, lazy loading configuration, and monitoring query execution. The skill helps you identify bottlenecks and apply targeted tuning.
Can jpa-patterns teach custom repository methods and projections?
Yes. jpa-patterns covers implementing custom repository methods using Spring Data's @Query annotation with both JPQL and native SQL. You'll learn DTO projections to fetch only required fields, reducing memory overhead and network traffic. The skill includes examples of interface-based and class-based projections for flexible data access patterns.
Does jpa-patterns include database migrations and testing best practices?
jpa-patterns includes database migration setup using Flyway with Spring Boot, covering versioning strategies and rollback patterns. For testing, you'll learn to set up test data access layers, use embedded databases like H2, and write integration tests for repositories. The skill emphasizes reproducible test environments and data consistency.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
JPA/Hibernate 模式
用于 Spring Boot 中的数据建模、仓库层(Repositories)实现和性能调优。
何时激活
- 设计 JPA 实体(Entities)和表映射
- 定义关联关系(@OneToMany、@ManyToOne、@ManyToMany)
- 优化查询(防止 N+1 问题、抓取策略、投影)
- 配置事务、审计(Auditing)或逻辑删除
- 设置分页、排序或自定义 Repository 方法
- 调优连接池(HikariCP)或二级缓存(Second-level Caching)
实体设计
@Entity
@Table(name = "markets", indexes = {
@Index(name = "idx_markets_slug", columnList = "slug", unique = true)
})
@EntityListeners(AuditingEntityListener.class)
public class MarketEntity {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 200)
private String name;
@Column(nullable = false, unique = true, length = 120)
private String slug;
@Enumerated(EnumType.STRING)
private MarketStatus status = MarketStatus.ACTIVE;
@CreatedDate private Instant createdAt;
@LastModifiedDate private Instant updatedAt;
}
启用审计(Auditing):
@Configuration
@EnableJpaAuditing
class JpaConfig {}
关联关系与防止 N+1 问题
```java @OneToMany(mappedBy = "market", cascade = CascadeType.ALL, orphanRemoval =
(truncated - see the full file via the links below)
File tree — 1 file
skills/jpa-patterns/SKILL.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Design JPA entities with relationships and optimize queries to prevent N+1 problems”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
This skill addresses the most common JPA performance bottlenecks: N+1 query problems, lazy loading errors, and transaction misconfigurations. It covers practical solutions like JOIN FETCH and EntityGraph for efficient data fetching, explains when to use LAZY vs EAGER loading, and demonstrates transaction management best practices for Spring applications.
Build data access layers with Spring Data JPA repository interfaces, entity relationships, and query patterns. Configure CRUD operations, derived and custom queries, pagination, database auditing, and transaction management. Includes best practices for performance optimization and entity design.
Java Rules enforces coding standards across style conventions, framework usage, design patterns, and security practices. It covers Spring Boot, Spring Data JPA, Hibernate, build tools, and modern Java features like records and pattern matching. Apply these rules when writing or reviewing Java code to maintain consistency and best practices.
Master Spring Boot architecture through practical patterns for REST API design, service layering, data access, caching, and async operations. Covers controller-service-repository organization, validation, exception handling, pagination, and observability for production-grade Java applications.
Connect Aurora, MySQL, or PostgreSQL databases to Spring Boot applications with production-ready patterns for datasource configuration, HikariCP pooling, SSL encryption, and credential management via AWS Secrets Manager. Includes read/write split setup for Aurora replicas, environment-specific profiles, and Flyway migration support.
Master Spring Data JPA entity design in Kotlin by learning why regular classes outperform data classes for persistence, how to implement stable identity and equality semantics, and when to enforce uniqueness at both database and application layers. Covers fetch strategies, common ORM traps, and Kotlin-specific patterns for preventing N+1 queries and lazy-loading errors.
More skills Java Jpa Hibernate (NOASSERTION) · springboot-patterns (Apache-2.0) · springboot-security (MIT)