jpa-patterns
Spring Boot中的JPA/Hibernate实体设计、关系、查询优化、事务、审计、索引、分页和连接池模式。
Skill by Luohaothu
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/luohaothu-jpa-patterns
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/jpa-patterns
What's inside
- Skill name
jpa-patterns- Description
- Spring Boot中的JPA/Hibernate实体设计、关系、查询优化、事务、审计、索引、分页和连接池模式。
- License
- MIT
- Instructions
- 142 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# JPA/Hibernate 模式
用于 Spring Boot 中的数据建模、存储库和性能调优。
## 实体设计
```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;
}
```
启用审计:
```java
@Configuration
@EnableJpaAuditing
class JpaConfig {}
```
## 关联关系和 N+1 预防
```java
@OneToMany(mappedBy = "market", cascade = CascadeType.ALL, orphanRemoval = true)
private List<PositionEntity> positions = new ArrayList<>();
```
* 默认使用延迟加载;需要时在查询中使用 `JOIN FETCH`
* 避免在集合上使用 `EAGER`;对于读取路径使用 DTO 投影
```java
@Query("select m from MarketEntity m left join fetch m.positions where m.id = :id")
Optional<MarketEntity> findWithPositions(@Param("id") Long id);
```
## 存储库模式
```java
public interface MarketRepository extends JpaRepository<MarketEntity, Long> {
Optional<MarketEntity> findBySlug(String slug);
@Query("select m from MarketEntity m where m.status = :status")
Page<MarketEntity> findByStatus(@Param("status") MarketStatus status, Pageable pageable);
}
```
* 使用投影进行轻量级查询:
```java
public interface MarketSummary {
Long getId();
String getName();
MarketStatus getStatus();
}
Page<MarketSummary> findAllBy(Pageable pageable);
```
## 事务
* 使用 `@Transactional` 注解服务方法
* 对读取路径使用 `@Transactional(readOnly = true)` 以进行优化
* 谨慎选择传播行为;避免长时间运行的事务
```java
@Transactional
public Market updateStatus(Long id, MarketStatus status) {
MarketEntity entity = repo.findById(id)
.orElseThrow(() -> new EntityNotFoundException("Market"));
entity.setStatus(status);
return Market.from(entity);
}
```
## 分页
```java
PageRequest page = PageRequest.of(pageNumber, pageSize, Sort.by("createdAt").descending());
Page<MarketEntity> markets = repo.findByStatus(MarketStatus.ACTIVE, page);
```
对于类似游标的分页,在 JPQL 中包含 `id > :lastId` 并配合排序。
## 索引和性能
* 为常用过滤器添加索引(`status`、`slug`、外键)
* 使用与查询模式匹配的复合索引(`status, created_at`)
* 避免 `select *`;仅投影需要的列
* 使用 `saveAll` 和 `hibernate.jdbc.batch_size` 进行批量写入
## 连接池 (HikariCP)
推荐属性:
```
spring.datasource.hikari.maximum-pool-size=20
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.validation-timeout=5000
```
对于 PostgreSQL LOB 处理,添加:From Luohaothu/everything-codex, MIT.
More from Luohaothu/everything-codex
- 0.493score
build-fix
Luohaothu
Build and compilation error resolution specialist.
SkillDFreshness: D★ 26Claude Code +9 - 0.493score
architect
Luohaothu
Software architecture specialist for system design, scalability, and technical decision-making.
SkillDFreshness: D★ 26Claude Code +9 - 0.490score
code-review
Luohaothu
Expert code review for quality, security, and maintainability.
SkillDFreshness: D★ 26Claude Code +9 - 0.490score
checkpoint
Luohaothu
Create or verify workflow checkpoints using git commits and state tracking.
SkillDFreshness: D★ 26Claude Code +9 - 0.487score
tdd-workflow
Luohaothu
在编写新功能、修复错误或重构代码时使用此技能。强制执行测试驱动开发,包含单元测试、集成测试和端到端测试,覆盖率超过80%。
SkillDFreshness: D★ 26Claude Code +9 - 0.487score
springboot-tdd
Luohaothu
使用JUnit 5、Mockito、MockMvc、Testcontainers和JaCoCo进行Spring Boot的测试驱动开发。适用于添加功能、修复错误或重构时。
SkillDFreshness: D★ 26Claude Code +9 - 0.487score
springboot-patterns
Luohaothu
Spring Boot 架构模式、REST API 设计、分层服务、数据访问、缓存、异步处理和日志记录。适用于 Java Spring Boot 后端工作。
SkillDFreshness: D★ 26Claude Code +9 - 0.487score
springboot-security
Luohaothu
Java Spring Boot 服务中关于身份验证/授权、验证、CSRF、密钥、标头、速率限制和依赖安全的 Spring Security 最佳实践。
SkillDFreshness: D★ 26Claude Code +9 - 0.484score
postgres-patterns
Luohaothu
基于Supabase最佳实践的PostgreSQL数据库模式,用于查询优化、架构设计、索引和安全。
SkillDFreshness: D★ 26Claude Code +9 - 0.484score
eval-harness
Luohaothu
克劳德代码会话的正式评估框架,实施评估驱动开发(EDD)原则
SkillDFreshness: D★ 26Claude Code +9 - 0.484score
continuous-learning-v2
Luohaothu
基于本能的学习系统,通过钩子观察会话,创建具有置信度评分的原子本能,并将其演化为技能/命令/代理。
SkillDFreshness: D★ 26Claude Code +9 - 0.484score
strategic-compact
Luohaothu
建议在逻辑间隔处进行手动上下文压缩,以在任务阶段中保留上下文,而非任意的自动压缩。
SkillDFreshness: D★ 26Claude Code +9
Signals
- Stars
- 26
- Forks
- 5
- Open issues
- 0
- Last commit (this folder)
- Feb 5, 2026 (8 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/Luohaothu/everything-codex
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from Luohaothu
- 0.493score
architect
Luohaothu
Software architecture specialist for system design, scalability, and technical decision-making.
SkillDFreshness: D★ 26Claude Code +9 - 0.493score
build-fix
Luohaothu
Build and compilation error resolution specialist.
SkillDFreshness: D★ 26Claude Code +9 - 0.490score
code-review
Luohaothu
Expert code review for quality, security, and maintainability.
SkillDFreshness: D★ 26Claude Code +9 - 0.490score
checkpoint
Luohaothu
Create or verify workflow checkpoints using git commits and state tracking.
SkillDFreshness: D★ 26Claude Code +9 - 0.487score
springboot-patterns
Luohaothu
Spring Boot 架构模式、REST API 设计、分层服务、数据访问、缓存、异步处理和日志记录。适用于 Java Spring Boot 后端工作。
SkillDFreshness: D★ 26Claude Code +9 - 0.487score
springboot-security
Luohaothu
Java Spring Boot 服务中关于身份验证/授权、验证、CSRF、密钥、标头、速率限制和依赖安全的 Spring Security 最佳实践。
SkillDFreshness: D★ 26Claude Code +9
Cite this page
jpa-patterns skill. Agent Mart. https://agentmart.dev/skills/luohaothu-jpa-patterns (last updated 2026-10-24)