commit
commit

Reputation: 4807

Criteria use aggregate function in order by clause

I have one criteria and i stuck with following:

I am using sql server so in my sql server I have following condition(Note: I am not putting whole query here I am just putting my order by clause)

order by (IIF(LEN(Code) = 1, '0'+Code ,Code))

"Code" is my column name, Now I want to implement same in hibernate in following

criteria.addOrder(Order.asc("CTC.code"));

Please help me out to achieve this. Any help will be appreciated.

Upvotes: 2

Views: 1810

Answers (1)

commit
commit

Reputation: 4807

After spending too much time and googling I found working solution from here:

http://blog.tremend.ro/2008/06/10/how-to-order-by-a-custom-sql-formulaexpression-when-using-hibernate-criteria-api/

In that example they have override Order class's method of criteria, I got what i was wanted, really charm for me.

Upvotes: 1

Related Questions