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.
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.
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.
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.
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With