Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use order by in HQL?

Tags:

I want to execute my HQL query like this:

Query queryPayment=sixSession.createQuery("from Payment where vcode=:p_Vcode or (Installment_Vcode=:installmentVcode and payment_date>:pdate) order byvcode."+order +"desc")         .setParameter("p_Vcode", p_Vcode)         .setParameter("installmentVcode", installmentVcode)         .setParameter("pdate", pdate); 

but it does not recognize +order+
I need the order by clause.

like image 547
AFF Avatar asked May 29 '12 07:05

AFF


People also ask

What is the use of ORDER BY clause in HQL?

Order by clause is used to retrieve the data from database in the sorted order by any property of returned class or components. HQL supports Order By Clause. In our example we will retrieve the data sorted on the userName type.

What is order by and group by in HQL?

Order by orders the data on the basis of given property in ascending or descending order. Group by groups the data on the basis of given property. In HQL we perform order by and group by for the given property of entity or associated entities. Find the complete example.

How do you sort results in HQL?

HQL – Sorting the Results To sort your HQL query’s results, you will need to use the order by clause. You can order the results by any property on the objects in the result set: either ascending (asc) or descending (desc). You can use order on more than one property in the query if you need to.

How do you use order by in SQL?

SQL ORDER BY Keyword ORDER BY. The ORDER BY command is used to sort the result set in ascending or descending order. The ORDER BY command... ASC. The ASC command is used to sort the data returned in ascending order. DESC. The DESC command is used to sort the data returned in descending order.


1 Answers

appears you have to put the "order by" in the HSQL query, but with a space:

"from Payment where vcode=:p_Vcode or (Installment_Vcode=:installmentVcode and payment_date>:pdate) order by vcode desc" 
like image 200
Alex Stybaev Avatar answered Sep 30 '22 01:09

Alex Stybaev