jpa-patterns
JPA/Hibernate patterns in Spring Boot for entity design, relationship handling, query optimization, transaction management, auditing, indexing, pagination, and connection pooling.
Machine translationRead the original Chinese text
Spring Boot中的JPA/Hibernate模式,用于实体设计、关系处理、查询优化、事务管理、审计、索引、分页和连接池。
Target: Target not categorized. Automatically collected · unverified.
Excerpt from the author’s documentation
Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.
Read the original Chinese text
Topics in the source
- JPA/Hibernate 模式
- 何时激活
- 实体设计
- 关联关系和 N+1 预防
- 存储库模式
- 事务
- 分页
- 索引和性能
用于 Spring Boot 中的数据建模、存储库和性能调优。 设计 JPA 实体和表映射时 定义关系时 (@OneToMany, @ManyToOne, @ManyToMany) 优化查询时 (N+1 问题预防、获取策略、投影) 配置事务、审计或软删除时 设置分页、排序或自定义存储库方法时 调整连接池 (HikariCP) 或二级缓存时 启用审计: 默认使用延迟加载;需要时在查询中使用 JOIN FETCH 避免在集合上使用 EAGER;对于读取路径使用 DTO 投影 使用投影进行轻量级查询: 使用 @Transactional 注解服务方法 对读取路径使用 @Transactional(readOnly = true) 以进行优化 谨慎选择传播行为;避免长时间运行的事务 对于类似游标的分页,在 JPQL 中包含 id > :lastId 并配合排序。 为常用过滤器添加索引(status、slug、外键) 使用与查询模式匹配的复合索引(status, createdat) 避免 select ;仅投影需要的列 使用 saveAll 和 hibernate.jdbc.batchsize 进行批量写入 推荐属性: 对于 PostgreSQL LOB 处理,添加: 一级缓存是每个 EntityManager 的;避免在事务之间保持实体 对于读取频繁的实体,谨慎考虑二级缓存;验证驱逐策略 使用 Flyway 或 Liquibase;切勿在生产中依赖 Hibernate 自动 DDL 保持迁移的幂等性和可添加性;避免无计划地删除列 首选使用 Testcontainers 的 @DataJpaTest 来镜像生产环境 使用日志断言 SQL 效率:设置 logging.level.org.hibernate.SQL=DEBUG 和 logging.level.org.hibernate.orm.jdbc.bind=TRACE 以查看参数值 请记住:保持实体精简,查询有针对性,事务简短。通过获取策略和投影来预防 N+1 问题,并根据读写路径建立索引。
- Source repository
- affaan-m/ECC
- Source file
- docs/zh-CN/skills/jpa-patterns/SKILL.md
- Fixed revision
- d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Sources and evidence
This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.
Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T15:01:42.389Z.
Categories are inferred from names, descriptions and paths. They do not establish compatibility.
License and attribution
MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.
Original license ↗Synchronization, copying and user-reported success do not mark a resource as runtime-tested.
Limitations and notes
- Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.