2012-05-29 65 views
10

我要執行這樣我的HQL查詢:如何在HQL中使用訂單?

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); 

,但它不承認+order+
我需要order by子句。

+2

好像你是「遞減」之前缺少空間,應和「降序」 – oers

回答

18

顯示你有「按訂單」的HSQL查詢放,但有一個空間:

"from Payment where vcode=:p_Vcode or (Installment_Vcode=:installmentVcode and 
payment_date>:pdate) order by vcode desc" 
+0

沒有,它返回一個錯誤: – AFF

+0

錯誤是:org.hibernate.hql.ast.QuerySyntaxException:意外的令牌:訂單近線1 – AFF

+0

我試過這個查詢:Query queryPayment = sixSession.createQuery(「from Payment where Vcode =:p_Vcode or 「+ order +」desc「) ,錯誤是:使用Hibernate核心會話/事務注入錯誤調用操作 org.hibernate.hql.ast.QuerySyntaxException:意外令牌:在第1行第127列附近訂購[來自information.Payment其中vcode =:p_Vcode或(Installment_Vcode =:installmentVcode和payment_date>:pdate)order by vcode order by vcode desc ] at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxExc – AFF