【问题标题】:Get all parents that do not have specific child and sort them获取所有没有特定孩子的父母并对其进行排序
【发布时间】:2013-10-12 14:05:59
【问题描述】:

我在制定以下查询时遇到问题。我有一个Parent.classChild.class。每个父母可以有很多孩子,每个孩子可以有很多父母,所以这是一个双向的多对多关联。

我需要获取所有没有特定孩子的父母并按某些属性对它们进行排序,例如。 parent.age.

this 问题中获得最多支持的答案看起来可以适应我的问题,但在 cmets 中说,使用子查询时无法按Parent 属性排序。

理想情况下,我想用 Criteria 来实现它,但 HQL 也可以..

【问题讨论】:

    标签: hibernate hql hibernate-criteria


    【解决方案1】:
    select distinct p from Parent p, Child c 
    where c.id = :childId
    and c not member of p.children
    order by p.age
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-29
      • 2015-08-30
      • 2018-01-12
      • 1970-01-01
      • 2020-11-16
      • 2018-03-18
      • 2021-12-02
      相关资源
      最近更新 更多