Jpa Patterns

JPA/Hibernate 模式,涵盖 Spring Boot 中的实体设计、关系、查询优化、事务、审计、索引、分页和连接池。

2,037 stars 332 forksOther Plugin marketplace

Install

Claude Code plugin
/plugin marketplace add xu-xiang/everything-claude-code-zh

The repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add xu-xiang/everything-claude-code-zh --skill jpa-patterns
Manual install
git clone --depth 1 https://github.com/xu-xiang/everything-claude-code-zh.git /tmp/everything-claude-code-zh
mkdir -p ~/.claude/skills
cp -r /tmp/everything-claude-code-zh/skills/jpa-patterns ~/.claude/skills/jpa-patterns

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# JPA/Hibernate 模式

用于 Spring Boot 中的数据建模、仓库层(Repositories)实现和性能调优。

## 何时激活

- 设计 JPA 实体(Entities)和表映射
- 定义关联关系(@OneToMany、@ManyToOne、@ManyToMany)
- 优化查询(防止 N+1 问题、抓取策略、投影)
- 配置事务、审计(Auditing)或逻辑删除
- 设置分页、排序或自定义 Repository 方法
- 调优连接池(HikariCP)或二级缓存(Second-level Caching)

## 实体设计

```java
@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):
```java
@Configuration
@EnableJpaAuditing
class JpaConfig {}
```

## 关联关系与防止 N+1 问题

```java
@OneToMany(mappedBy = "market", cascade = CascadeType.ALL, orphanRemoval = true)
private List<PositionEntity> positions = new ArrayList<>();
```

- 默认使用延迟加载(Lazy Loading);必要时在查询中使用 `JOIN FETCH`
- 避免在集合上使用 `EAGER`;在读取路径中使用 DTO 投影(Projections)

```java
@Query("select m from MarketEntity m left join fetch m.positions where m.id = :id")
Optional<MarketEntity> findWithPositions(@Param("id") Long id);
```

## Repository 模式
Read the full skill on GitHub

Details

Skill name
jpa-patterns
Path
skills/jpa-patterns/SKILL.md
License
MIT
Repo updated
5 March 2026

FAQ

What does the Jpa Patterns skill do?

JPA/Hibernate 模式,涵盖 Spring Boot 中的实体设计、关系、查询优化、事务、审计、索引、分页和连接池。

How do I install the Jpa Patterns skill?

Claude Code plugin: /plugin marketplace add xu-xiang/everything-claude-code-zh. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Jpa Patterns popular?

It lives in xu-xiang/everything-claude-code-zh, which has 2,037 GitHub stars and 332 forks.

Related skills

Browse the most popular Claude skills, all other skills, or write your own with the skills generator.