24

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.

oers
  • 18,436
  • 13
  • 66
  • 75
AFF
  • 1,515
  • 4
  • 21
  • 35

1 Answers1

34

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"
rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Alex Stybaev
  • 4,623
  • 3
  • 30
  • 44
  • 1
    error is: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: order near line 1 – AFF May 29 '12 at 08:06
  • I have tried this query:Query queryPayment=sixSession.createQuery("from Payment where vcode=:p_Vcode or (Installment_Vcode=:installmentVcode and payment_date>:pdate) order by vcode ." +order+" desc") and the error is:Error invoking Action using Hibernate Core Session / Transaction injection org.hibernate.hql.ast.QuerySyntaxException: unexpected token: order near line 1, column 127 [from information.Payment where vcode=:p_Vcode or (Installment_Vcode=:installmentVcode and payment_date>:pdate) order by vcode order by vcode desc] at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxExc – AFF May 29 '12 at 08:32
  • 1
    try the query from my answer instead. – Alex Stybaev May 29 '12 at 08:39