开发者

Is it possible to remove order from Hibernate Criteria?

If I have an @OrderBy("someProperty") annotation on an object and then use a Criteria开发者_JS百科 to add an ORDER BY clause like so:

criteria.addOrder(Order.asc("id"));

The resulting SQL will do the ordering like this:

ORDER BY someProperty, id asc

Is it possible to change the order of the two or to remove the someProperty order? I can't remove the @OrderBy annotation and I'm using Hibernate for Java.


Criteria has no methods for removal of Order neither Criterion Order class is very limited, you can only use property names and it generates standard and portable SQL. OrderBy annotation is a SQL order, as javadoc states: OrderBy That means you can use there any sql (even a exclusive one of your database vendor). Take a look at these article: Sorting Collections in Hibernate Using SQL in @OrderBy

Adding a SQL fragment into your domain class isn't necessarily the most elegant thing in the world, but it might be the most pragmatic thing.


It may be possible to remove particular ordering via criteria.iterateOrderings() iterator, but I'm not sure how it works with annotations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜