HQL在一个集合中排序 [英] HQL order by within a collection

查看:126
本文介绍了HQL在一个集合中排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个实体:汽车和车轮(oneToMany),我想要检索我的车,所有的车轮和(这是棘手的部分)wheel.location。下面的代码抛出一个异常,并显示非法尝试解除引用集合的消息。

 从Car $中选择c 
b $ b LEFT JOIN FETCH c.wheels
order by c.wheels.location

任何想法如何做到这一点,如果这可能在HQL?

解决方案

  SELECT DISTINCT c 
FROM car
LEFT JOIN FETCH c.wheels AS wheel
ORDER BY wheels.location


I have 2 entities: car and wheels (oneToMany) and I want to retrieve my car, with all the wheels and (this is the tricky part) ordered by wheels.location. The below code throws an exception with the message "illegal attempt to dereference collection."

Select c
  from Car
       LEFT JOIN FETCH c.wheels
order by c.wheels.location

Any idea how to do this and if this is possible in HQL?

解决方案

SELECT DISTINCT c
  FROM Car
       LEFT JOIN FETCH c.wheels AS wheels
ORDER BY wheels.location

这篇关于HQL在一个集合中排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆