休眠排序在SQL中 [英] Hibernate ordering in sql

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

问题描述

是否可以在不使用 SortedSet 接口的情况下使用hibernate对集合进行排序,而不使用 @OrderBy 注释 - 只是使用标准的addOrder。



我试过了,它添加了order by子句,没有排序。

我使用hibernate 3.4。

解决方案

即使集合映射支持顺序,NHibernate集合也没有顺序。请参阅Ayende的解释

< blockquote>

请注意,[order-by]不能用于泛型集合,一般而言,
您不想依赖这些排序属性,您想使用
所选藏品的自然属性。集合是
定义的无序的唯一元素集合。

您可以将order by子句追加到底层的SQL ,但是当NHibernate创建集合时,这个顺序就会丢失。当然,使用有序集合或其他集合类型(包或列表)也是可行的。

Is it possible to sort the Set collection using hibernate, in sql without using SortedSet interface, without using @OrderBy annotation - just using criteria's addOrder.

I've tried it and it adds order by clause but the set isn't sorted.

I use hibernate 3.4.

解决方案

NHibernate Sets don't have "order" even though the set mapping supports an order-by. See Ayende's explanation:

Note that [order-by] does not work with generic sets and that in general, you don’t want to rely on those ordering properties, you want to use the natural properties of the selected collection. Sets are, by definition, unordered set of unique elements.

You can append the order by clause to the underlying SQL, but that order is lost when NHibernate builds the set. Using an "ordered" set or other collection type (bag or list) will work, of course.

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

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