[英]hql - order by first item of the list
So I have a requirement that would need me to order the results by the id of the first item of the list. 因此,我有一个要求,我需要按列表第一项的ID对结果进行排序。
public class Order {
private int id;
private List<Item> items;
}
To get an order where the list items contains '1234', I can do something like this: 要获得一个列表项包含“ 1234”的订单,我可以执行以下操作:
from Order o where o.items[0].id = 1234
Back to my requirement, I thought this would work but it didn't: 回到我的要求,我认为这可以工作,但是没有:
from Order o order by o.items[0].id
Any ideas? 有任何想法吗? Thanks!
谢谢!
I believe I tried that before; 我相信我曾经尝试过; and I don't think it is possible to do it through a list.
而且我认为不可能通过列表来做到这一点。 If you had another column that is Item, then you can do it like order by o.item.id or if you add Item table to the join then order that way.
如果您有另一个列是Item,则可以通过o.item.id进行排序,也可以将Item表添加到联接中,然后以这种方式进行排序。
如果你的意思是值的最低ID item
也不会做这你想要什么?
select distinct o from Order o join o.items item order by item.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.