QueryException: could not resolve property: DESC

2019-08-30 11:52发布

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条回答
我只想做你的唯一
2楼-- · 2019-08-30 12:22

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"; 
查看更多
登录 后发表回答