QueryException:无法解析属性:DESC [英] QueryException: could not resolve property: DESC

查看:108
本文介绍了QueryException:无法解析属性:DESC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用JPA计算几行.

I want to count the several rows using JPA.

我的代码:

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:

原因:org.hibernate.QueryException:无法解析属性:DESC.

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?

推荐答案

在查询中,Orderby之后仅指定列名,如

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

这篇关于QueryException:无法解析属性:DESC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆