如何通过集合中对象的属性订购HQL查询?

时间:2012-01-19 04:21:09

标签: hibernate grails hql gorm

假设我有一台带收音机的汽车,收音机与Button有一对多关联。我想要的是福特汽车制造的所有按钮的唯一名称,按Button名称排序。鉴于我们建立关系的方式,我无法弄清楚如何做到这一点。类似的东西:

select distinct elements(c.radio.buttons)
from Car c 
where c.make = 'Ford'
order by c.radio.buttons.name

当然,最后一部分是错误的。我打算对这些数据进行分页,这就是为什么我要在查询中完全完成它。

答案可能涉及联接获取但到目前为止我没有运气。谢谢!

1 个答案:

答案 0 :(得分:6)

HQL将是

select distinct button
from Car c join c.radio.buttons button
where c.make = 'Ford'
order by button.name