【发布时间】:2017-02-23 13:19:54
【问题描述】:
我使用 WrappedBean 进行了这个查询:
buffer.append("SELECT new myPackage.WrappedBean(E.debitant.id, E.dateCalcul, E.verse, E.incidenceReprise, E.soldeSoumission) ");
buffer.append("FROM " + getEntityClassName() + " E ");
buffer.append("LEFT JOIN E.debitant DT ");
buffer.append("WHERE E.debitant.id = :idDebitant ");
buffer.append("AND YEAR(E.dateCalcul) = :year ");
buffer.append("GROUP BY E.debitant.id");
hqlQuery = session.createQuery(buffer.toString());
hqlQuery.setInteger("idDebitant", idDebitant);
hqlQuery.setInteger("year", year);
我创建了 WrappedBean 来返回一些列和使用 Group BY。
当我尝试执行它时,我得到这个错误:
org.postgresql.util.PSQLException: ERREUR: «complement0_.date_calcul» 列必须出现在 GROUP BY 子句中或必须在 Select 中使用(我将错误翻译成法语)
我的 POSTGRES 查询在 Group BY 中不包含 date_calcul。
另一个问题,在我的查询中我也有这个:
SUM(CASE WHEN YEAR(dateCalcul)=@PECAnnee AND verse>0 THEN verse ELSE 0 END)
我知道在 HQL 中,我们不能在选择时做大小写,因此,我不将 SUM 添加到列 verse
我忘记了什么?
【问题讨论】: