QueryException: could not resolve property: DESC

对着背影说爱祢 提交于 2019-12-13 03:46:27

问题


I want to count the several rows using JPA.

My Code:

String hql = "SELECT count(e.id) as count, e.status, e.error_class, e.error_message, e.id, e.settlement_status_raw FROM " + PaymentTransactions.class.getName() + " e WHERE e.terminal_id = :terminal_id AND (e.createdAt > :created_at) AND (e.status != 'approved') GROUP BY e.error_message ORDER BY count DESC";  
TypedQuery<PaymentTransactions> query = entityManager.createQuery(hql, PaymentTransactions.class).setParameter("terminal_id", terminal_id).setParameter("created_at", created_at);
List<PaymentTransactions> paymentTransactions = query.getResultList();
return paymentTransactions;

But I got an error:

Caused by: org.hibernate.QueryException: could not resolve property: DESC.

Count is not present into the entity but I want to return it as a value. What is the proper way to implement this?


回答1:


In Query,after Orderby only specify the column name like,

String hql = "SELECT count(e.id) as count, e.status, e.error_class, e.error_message, e.id, e.settlement_status_raw FROM " + PaymentTransactions.class.getName() + " e WHERE e.terminal_id = :terminal_id AND (e.createdAt > :created_at) AND (e.status != 'approved') GROUP BY e.error_message ORDER BY e.id DESC"; 


来源:https://stackoverflow.com/questions/57137467/queryexception-could-not-resolve-property-desc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!