412-frameworks-quarkus-panache

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Hibernate ORM with Panache

Hibernate ORM with Panache

Apply Panache patterns for Hibernate ORM in Quarkus.
What is covered in this Skill?
  • Active record (PanacheEntity) vs PanacheRepository — when to use each
  • Parameterized HQL / Panache queries: positional (?1) and named (:param) — no unsafe concatenation
  • @NamedQuery on entities for reusable, build-time validated queries
  • DTO projections with project(Class) to avoid exposing managed entities
  • Pagination with Page.of(pageIndex, pageSize) and query.count()
  • N+1 avoidance with JOIN FETCH in HQL queries
  • Optimistic locking with @Version and handling OptimisticLockException
  • @Transactional application services
  • @TestTransaction for automatic rollback in @QuarkusTest tests
  • Mapping entities vs exposing DTOs at REST boundaries
  • Pairing with
    @411
    for raw SQL when needed
Scope: Apply recommendations based on the reference rules and good/bad code examples.
在Quarkus中应用Panache模式操作Hibernate ORM。
本Skill涵盖哪些内容?
  • 活动记录模式(PanacheEntity)与PanacheRepository的对比——各自的适用场景
  • 参数化HQL/Panache查询:位置参数(?1)和命名参数(:param)——避免不安全的字符串拼接
  • 在实体上使用@NamedQuery实现可复用、构建时验证的查询
  • 使用project(Class)进行DTO投影,避免暴露托管实体
  • 结合Page.of(pageIndex, pageSize)和query.count()实现分页
  • 在HQL查询中使用JOIN FETCH避免N+1查询问题
  • 使用@Version实现乐观锁并处理OptimisticLockException
  • @Transactional应用服务
  • 在@QuarkusTest测试中使用@TestTransaction实现自动回滚
  • 在REST边界处映射实体与暴露DTO的对比
  • 必要时搭配
    @411
    使用原生SQL
范围: 根据参考规则和代码示例的优劣来应用相关建议。

Constraints

约束条件

Compile before persistence changes; verify after.
  • MANDATORY: Run
    ./mvnw compile
    or
    mvn compile
    before applying any change
  • PREREQUISITE: Project must compile before applying Panache improvements
  • SAFETY: If compilation fails, stop immediately
  • BLOCKING CONDITION: Compilation errors must be resolved by the user before proceeding
  • VERIFY: Run
    ./mvnw clean verify
    or
    mvn clean verify
    after applying improvements
  • BEFORE APPLYING: Read the reference for detailed rules and examples
在修改持久化代码前先编译;修改后进行验证。
  • 强制要求:在进行任何修改前运行
    ./mvnw compile
    mvn compile
  • 前提条件:在应用Panache优化前,项目必须能正常编译
  • 安全要求:如果编译失败,立即停止操作
  • 阻塞条件:用户必须先解决编译错误才能继续
  • 验证步骤:应用优化后运行
    ./mvnw clean verify
    mvn clean verify
  • 应用前须知:阅读参考文档了解详细规则和示例

When to use this skill

何时使用本Skill

  • Review Panache entities or repositories in Quarkus
  • Improve Hibernate ORM data access with Panache
  • Add DTO projections, JOIN FETCH, pagination, or optimistic locking to Panache queries
  • Fix N+1 query problems or add @Version concurrency control in Quarkus Panache
  • 评审Quarkus中的Panache实体或仓库
  • 使用Panache优化Hibernate ORM数据访问
  • 为Panache查询添加DTO投影、JOIN FETCH、分页或乐观锁
  • 修复Quarkus Panache中的N+1查询问题或添加@Version并发控制

Reference

参考文档

For detailed guidance, examples, and constraints, see references/412-frameworks-quarkus-panache.md.
如需详细指导、示例和约束条件,请查看references/412-frameworks-quarkus-panache.md