有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java按计数排序HQL

我试图根据Student的数量对School进行排序。它们之间存在ManyToOne/OneToMany关系

这不起作用,但这是我到目前为止所做的

from School s order by count(s.students)

我宁愿不使用标准,因为我必须重构很多代码。有没有办法通过HQL实现这一点


共 (1) 个答案

  1. # 1 楼答案

    好吧,我知道了。这奏效了

    from School s order by size(s.students)

    根据Hibernate文档

    You can test the size of a collection with the special property size or the special size() function.