Reputation: 1819
If I have an @OrderBy("someProperty") annotation on an object and then use a Criteria 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.
Upvotes: 9
Views: 4122
Reputation: 65
It may be possible to remove particular ordering via criteria.iterateOrderings() iterator, but I'm not sure how it works with annotations.
Upvotes: 2
Reputation: 295
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.
Upvotes: 2