【问题标题】:How to filter fields owned by a foreign-key-referred-model with HQL?如何使用 HQL 过滤外键引用模型拥有的字段?
【发布时间】:2017-10-04 14:31:27
【问题描述】:

例如模型 Comment 有字段:

  • content
  • account(参考型号Account
  • article(参考型号Article

现在如果我想在查询时过滤整个article字段,我可以为类Comment定义一个没有content的构造方法,例如:

public Comment(String content, Account account) {
    this.content = content;
    this.account = account;
}

并定义查询:

@Query("SELECT NEW Comment(content, account) FROM Comment WHERE channel_id = ?1")
List<Comment> findCommentsByChannel_Id(Long channel_id);

但是现在我也想过滤字段account的字段password,怎么实现呢?

【问题讨论】:

    标签: spring hibernate jpa spring-data hql


    【解决方案1】:

    只需使用您要保留的属性创建Projections

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-18
      • 1970-01-01
      • 2022-11-09
      • 2015-07-26
      • 1970-01-01
      • 2021-10-16
      • 2021-12-09
      相关资源
      最近更新 更多