我在编写以下查询时遇到麻烦。我有一个Parent.class
和Child.class
。每个父母可以有很多孩子,每个孩子可以有很多父母,因此这是双向的多对多关联。
我需要让所有没有具体孩子的父母,并按某些属性对他们进行排序。parent.age
。
在该问题中大多数赞成的答案似乎可以针对我的问题进行调整,但是在评论中说,使用子查询时,无法按Parent
属性进行排序。
理想情况下,我希望使用Criteria实现它,但是HQL也可以。
select distinct p from Parent p, Child c
where c.id = :childId
and c not member of p.children
order by p.age
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句