2012-05-29 20 views
10

Tôi muốn thực hiện truy vấn HQL của tôi như thế này:Tôi làm cách nào để sử dụng đơn đặt hàng bằng 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); 

nhưng nó không nhận ra +order+
tôi cần thứ tự bằng khoản.

+2

có vẻ như bạn đang thiếu một không gian trước khi "desc", shold được "desc" – oers

Trả lời

18

xuất hiện bạn phải đặt "tự do" trong truy vấn HSQL, nhưng với một không gian:

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

Không, nó trả về lỗi: – AFF

+0

lỗi là: org.hibernate.hql.ast.QuerySyntaxException: mã thông báo không mong muốn: lệnh gần dòng 1 – AFF

+0

Tôi đã thử truy vấn này: Truy vấn truy vấnPayment = sixSession.createQuery ("từ Thanh toán trong đó vcode =: p_Vcode hoặc (Installment_Vcode =: installmentVcode và payment_date>: pdate) theo thứ tự vcode. "+ Order +" desc ") và lỗi là: Lỗi khi gọi Hành động bằng Hibernate Core Session/Transaction injection org.hibernate.hql.ast.QuerySyntaxException: mã thông báo không mong muốn: đặt hàng gần dòng 1, cột 127 [từ thông tin.Thanh toán nơi vcode =: p_Vcode hoặc (Installment_Vcode =: installmentVcode và payment_date>: pdate) theo thứ tự mã hóa bằng vcode desc ] tại org.hibernate.hql.ast.QuerySyntaxException.convert (QuerySyntaxExc – AFF

Các vấn đề liên quan