Reputation: 253
I am now facing a problem about Sorting the result getting from DB. I want to sort by ASC but I want to make an exception , "OTHERS". So the selection "Others" will be at last of the selection. How can i implement this? So, the ComboBox List will like this :
AA
BB
CC
DD
......
......
XX
YY
ZZ
Others
Code i tried:
public List<Testing> findAll() {
Criteria criteria = getSession().createCriteria(Testing.class);
criteria.addOrder(Order.asc("TestingString"));
return (List<Testing>) criteria.list();
}
By using this coding, "Others" will between "OO" and "PP". It is a bad way to show the selection "Others".
Upvotes: 0
Views: 38
Reputation: 57381
On hibernate you can define a @Formula annotated field where the value is SQL representation of the order. Then use the @Formula annotated field in your sort.
The expression could be
CASE columnName
WHEN 'Other' THEN 'zzzzzzzzzzzzzz"
ELSE columnName
END
Upvotes: 0
Reputation: 4361
No straightforward way with Hibernate, but you can totally do that in your code. I think of 2 ways:
Upvotes: 1