بنقرة واحدة
java-jpa-hibernate
精通 JPA/Hibernate - 实体设计、查询、事务、性能优化
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
精通 JPA/Hibernate - 实体设计、查询、事务、性能优化
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Execute Story design review for an Epic or single Story using parallel three-layer adversarial analysis (Structure Hunter, Consistency Checker, Contract Auditor) with four-bucket triage, and save review summary to a structured result file. Use when user mentions 'SR', 'story review', 'story design review', 'epic review', 'story check', 'design review', 'Story 审查', 'SR 审查', '设计审查', 'Story 设计审查', 'Epic 审查', '审查 Story', '审查 Epic', or wants to review Story design documents before development. Capable of dual-granularity review (Epic-level or single-Story), parallel three-layer adversarial analysis, four-bucket triage, auto-detecting review history, batch processing, and generating structured review result documents with round numbering.
Evaluate Story design review results and generate a structured evaluation document. Use when user mentions 'SR evaluate', 'SR evaluation', 'evaluate SR', 'story review evaluation', 'design review evaluation', '评估 SR', '评估审查结果', 'SR 评估', '设计审查评估', 'Story 审查评估', '评估 Story 审查', or wants to assess Story design review findings. Capable of reading latest review results, assessing finding validity with source and bucket awareness, and producing evaluation documents with round numbering.
Execute Story document revisions based on SR evaluation conclusions and append revision summary to the evaluation document. Use when user mentions 'SR fix', 'SR revise', 'story revision', 'apply SR fixes', 'story review fix', 'design fix', '执行修订', 'SR 修订', '修订 Story', '执行 SR 修正', 'Story 设计修订', '修订 Story 文档', or wants to implement revisions from SR evaluation. Capable of reading evaluation conclusions, executing targeted document revisions, and recording revision summaries in evaluation documents.
Execute cross-LLM code review for a Story using parallel adversarial review layers (Blind Hunter, Edge Case Hunter, Acceptance Auditor) with structured triage, and save review summary to a structured result file. Use when user mentions 'CR', 'code review', 'crossllm review', 're-review', 'code review summary', '代码审查', 'CR 审查', '跨模型审查', '代码复审', '代码评审', '审查代码', or wants to review Story code changes. Capable of first-round and subsequent-round code reviews, parallel three-layer adversarial analysis, four-bucket triage, auto-detecting review history, and generating structured review result documents with round numbering.
Evaluate code review results from a cross-LLM review round and generate a structured evaluation document. Use when user mentions 'CR evaluate', 'CR evaluation', 'evaluate CR', 'review assessment', 'code review evaluation', '评估审查结果', '评估 CR', '评估 CR 结果', 'CR 评估', '审查结果评估', 'CR 结果评估', '代码审查评估', or wants to assess code review findings. Capable of reading latest review results, assessing finding validity, and producing evaluation documents with round numbering.
Execute code fixes based on code review evaluation conclusions and append fix summary to the evaluation document. Use when user mentions 'CR fix', 'CR repair', 'execute fix', 'apply CR fixes', 'code review fix', '执行修复', 'CR 修复', '修复 CR 问题', '执行 CR 修正', '代码审查修复', or wants to implement fixes from CR evaluation. Capable of reading evaluation conclusions, executing targeted code fixes, and recording fix summaries in evaluation documents.
استنادا إلى تصنيف SOC المهني
| name | java-jpa-hibernate |
| description | 精通 JPA/Hibernate - 实体设计、查询、事务、性能优化 |
| sasmp_version | 1.3.0 |
| version | 3.0.0 |
| bonded_agent | 06-java-persistence |
| bond_type | PRIMARY_BOND |
| allowed-tools | Read, Write, Bash, Glob, Grep |
| parameters | {"database":{"type":"string","enum":["postgresql","mysql","oracle","h2"],"description":"目标数据库"},"focus":{"type":"string","enum":["entities","queries","transactions","caching"],"description":"主题聚焦方向"}} |
掌握 JPA 和 Hibernate 的数据持久化,构建生产级应用。
本技能涵盖 JPA 实体设计、Hibernate 优化、Spring Data Repository、查询策略和缓存。重点关注防止 N+1 查询问题和构建高性能持久层。
当你需要:
// 带关联关系的实体
@Entity
@Table(name = "orders")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customer_id", nullable = false)
private Customer customer;
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true)
@BatchSize(size = 20)
private List<OrderItem> items = new ArrayList<>();
@Version
private Long version;
// 双向关联辅助方法
public void addItem(OrderItem item) {
items.add(item);
item.setOrder(this);
}
}
// 审计基类
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class Auditable {
@CreatedDate
@Column(updatable = false)
private Instant createdAt;
@LastModifiedDate
private Instant updatedAt;
}
// 带查询优化的 Repository
public interface OrderRepository extends JpaRepository<Order, Long> {
// 使用 JOIN FETCH 防止 N+1
@Query("SELECT DISTINCT o FROM Order o JOIN FETCH o.items WHERE o.status = :status")
List<Order> findByStatusWithItems(@Param("status") Status status);
// EntityGraph 替代方案
@EntityGraph(attributePaths = {"items", "customer"})
Optional<Order> findById(Long id);
// DTO 投影
@Query("SELECT new com.example.OrderSummary(o.id, o.status, c.name) " +
"FROM Order o JOIN o.customer c WHERE o.id = :id")
Optional<OrderSummary> findSummaryById(@Param("id") Long id);
}
| 策略 | 使用场景 | 示例 |
|---|---|---|
| JOIN FETCH | 总是需要关联数据时 | JOIN FETCH o.items |
| EntityGraph | 动态抓取时 | @EntityGraph(attributePaths) |
| @BatchSize | 集合访问时 | @BatchSize(size = 20) |
| DTO 投影 | 只读查询时 | new OrderSummary(...) |
spring:
jpa:
open-in-view: false # 关键配置!
properties:
hibernate:
jdbc.batch_size: 50
order_inserts: true
order_updates: true
default_batch_fetch_size: 20
generate_statistics: ${HIBERNATE_STATS:false}
datasource:
hikari:
maximum-pool-size: 20
minimum-idle: 5
leak-detection-threshold: 60000
| 问题 | 原因 | 解决方案 |
|---|---|---|
| N+1 查询 | 循环中延迟加载 | JOIN FETCH、EntityGraph |
| LazyInitException | Session 已关闭 | 使用 DTO 投影 |
| 查询缓慢 | 缺少索引 | EXPLAIN ANALYZE |
| 连接泄漏 | 缺少 @Transactional | 添加注解 |
spring.jpa.show-sql=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.orm.jdbc.bind=TRACE
hibernate.generate_statistics=true
□ 启用 SQL 日志
□ 检查每个请求的查询次数
□ 验证抓取策略
□ 审查 @Transactional
□ 检查连接池
Skill("java-jpa-hibernate")
java-performance - 查询优化java-spring-boot - Spring Data