使用JPQL / HQL在JPA中对连接提取集合进行排序 [英] Ordering a join fetched collection in JPA using JPQL/HQL

查看:179
本文介绍了使用JPQL / HQL在JPA中对连接提取集合进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于以下JPQL语句,如何修改它以便结果列表中的小猫按其 age 属性排序?

Given the below JPQL statement, how do I modify it so that the kittens in the resulting list are ordered by their age property?

SELECT c FROM Cat c left join fetch c.kittens WHERE c.id = :id

我尝试了多个approches,但没有运气。这实际上是我想要做的,但它不起作用:

I've tried multiple approches but without any luck. This is esentially what I would like to do, but it doesn't work:

SELECT c FROM Cat c left join fetch c.kittens k WHERE c.id = :id ORDER BY k.age


推荐答案

Hej,

我不认为在使用查询时应用这种方法。但据我记忆,你可以使用它在映射中为你的集合添加默认排序:

I don't think this is possible when applied using queries. But as far as I remember, you can use this to add default ordering to your collection in the mapping:

@OrderBy("myColumName asc")

这篇关于使用JPQL / HQL在JPA中对连接提取集合进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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