jpa-patterns
Skill43 starsChanged 10 months agoMITView on GitHub
Spring Boot 中用于实体设计、关联关系、查询优化、事务、审计、索引、分页和连接池的 JPA/Hibernate 模式。
18 other projects use a version of this, 14 of them edited.
Adopted by
Most recently taken up by
- templetongroup/radiantedited, first seen Sep 17, 2026
- decebals/claude-code-javatheir own version, first seen Sep 6, 2026
- SamuelNDCE/claude-super-skill-libraryedited, first seen Aug 1, 2026
- JunMystery/Agent-Guidance-Pythonedited, first seen Jul 21, 2026
- Lukasbrujula/claude-code-frameworkedited, first seen Jul 6, 2026
- piomin/spring-boot-app-with-claudecodetheir own version, first seen May 26, 2026
Used with
Projects with it also use kotlin-testing, nuxt4-patterns and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
tpavanipradeepSkillkotlin-testing
Kotlin testing patterns with Kotest, MockK, coroutine testing, property-based testing, and Kover coverage. Follows TDD methodology with idiomatic Kotlin practices.
Also in 6 projects that use this
mryeastcodeSkillnuxt4-patterns
Nuxt 4 app patterns for hydration safety, performance, route rules, lazy loading, and SSR-safe data fetching with useFetch and useAsyncData.
Also in 5 projects that use this
InfopibeSkillralphinho-rfc-pipeline
RFC-driven multi-agent DAG execution pattern with quality gates, merge queues, and work unit orchestration.
Also in 9 projects that use this
saxon-ySkillconfigure-ecc
Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.
Also in 11 projects that use this
InfopibeSkillcontent-hash-cache-pattern
Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.
Also in 10 projects that use this
mryeastcodeSkillsanta-method
Multi-agent adversarial verification with convergence loop. Two independent review agents must both pass before output ships.
Also in 6 projects that use this
- +4 more from Infopibe
Other versions18 projects use a version of this.
Word for word · 0
None found.
Edited · 14
- xu-xiang/everything-claude-code-zh★ 2k57% same
- loulanyue/awesome-claude-notes★ 27238% same
- tpavanipradeep/everything-claude-code★ 13438% same
- templetongroup/radiant★ 11337% same
- Jamkris/everything-gemini-code★ 8742% same
- FaisalAlqarni/sp-ecc★ 942% same
- Infopibe/everything-claude-code★ 838% same
- Lukasbrujula/claude-code-framework★ 442% same
- JunMystery/Agent-Guidance-Python★ 238% same
- ashutoshrathi0909-oss/everything-claude-code★ 138% same
4 more not listed
Wrote their own version · 4
- piomin/claude-ai-spring-boot★ 1.3ksame name
- decebals/claude-code-java★ 747same name
- minghaoZhangZ/shipkit★ 1same name
- piomin/spring-boot-app-with-claudecode★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository30 other files it gives its agents.
- rules/agents.mdAGENTS.md
- examples/CLAUDE.mdCLAUDE.md
- oneskillSkill
- backend-patternsSkill
- clickhouse-ioSkill
- coding-standardsSkill
- continuous-learningSkill
- continuous-learning-v2Skill
- django-patternsSkill
- django-securitySkill
- django-tddSkill
- django-verificationSkill
- eval-harnessSkill
- frontend-patternsSkill
- golang-patternsSkill
- golang-testingSkill
- iterative-retrievalSkill
- java-coding-standardsSkill
- postgres-patternsSkill
- project-guidelines-exampleSkill
- python-patternsSkill
- python-testingSkill
- security-reviewSkill
- springboot-patternsSkill
- springboot-securitySkill
- springboot-tddSkill
- springboot-verificationSkill
- strategic-compactSkill
- tdd-workflowSkill
- verification-loopSkill
The file
Files
JPA/Hibernate 模式
用于 Spring Boot 中的数据建模、存储层(Repositories)开发和性能调优。
实体设计(Entity Design)
@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 问题预防
@OneToMany(mappedBy = "market", cascade = CascadeType.ALL, orphanRemoval = true)
private List<PositionEntity> positions = new ArrayList<>();- 默认使用懒加载(Lazy loading);必要时在查询中使用
JOIN FETCH - 避免在集合上使用立即加载(
EAGER);对于读取路径,优先使用 DTO 投影(Projections)
@Query("select m from MarketEntity m left join fetch m.positions where m.id = :id")
Optional<MarketEntity> findWithPositions(@Param("id") Long id);存储层模式(Repository Patterns)
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);
}- 使用投影(Projections)进行轻量级查询:
public interface MarketSummary {
Long getId();
String getName();
MarketStatus getStatus();
}
Page<MarketSummary> findAllBy(Pageable pageable);事务(Transactions)
- 使用
@Transactional注解 Service 方法 - 在读取路径上使用
@Transactional(readOnly = true)进行优化 - 谨慎选择传播行为(Propagation);避免长事务
@Transactional
public Market updateStatus(Long id, MarketStatus status) {
MarketEntity entity = repo.findById(id)
.orElseThrow(() -> new EntityNotFoundException("Market"));
entity.setStatus(status);
return Market.from(entity);
}分页(Pagination)
PageRequest page = PageRequest.of(pageNumber, pageSize, Sort.by("createdAt").descending());
Page<MarketEntity> markets = repo.findByStatus(MarketStatus.ACTIVE, page);对于游标式分页(Cursor-like pagination),请在 JPQL 中包含 id > :lastId 并配合排序。
索引与性能
- 为常用过滤器(
status、slug、外键)添加索引(Indexing) - 使用匹配查询模式的复合索引(Composite indexes,如
status, created_at) - 避免使用
select *;仅投影所需的列 - 使用
saveAll并配置hibernate.jdbc.batch_size进行批量写入
连接池(Connection Pooling - 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 处理,请添加:
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true缓存(Caching)
- 一级缓存(1st-level cache)是基于 EntityManager 的;避免跨事务保留实体
- 对于读多写少的实体,谨慎考虑二级缓存(2nd-level cache);验证逐出策略(Eviction strategy)
数据迁移(Migrations)
- 使用 Flyway 或 Liquibase;在生产环境中绝不要依赖 Hibernate 的自动 DDL
- 保持迁移是幂等(Idempotent)且具有增量性的;避免在没有计划的情况下删除列
测试数据访问
- 优先使用
@DataJpaTest配合 Testcontainers 来模拟生产环境 - 使用日志断言 SQL 效率:设置
logging.level.org.hibernate.SQL=DEBUG以及logging.level.org.hibernate.orm.jdbc.bind=TRACE以查看参数值
记住:保持实体精简、查询意图明确且事务简短。通过抓取策略(Fetch strategies)和投影(Projections)来防止 N+1 问题,并针对读/写路径建立索引。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

