简体   繁体   English

Hibernate GROUP BY对Oracle无效

[英]Hibernate GROUP BY invalid for Oracle

I created an Hibernate query like this: 我创建了一个Hibernate查询,如下所示:

select new ProjectForUser
  (p.projectId, p.name, p.description, p.client, p.startDate, p.endDate,
   p.liveDate, p.projectState, p.overallRagStatus, p.scopeRagStatus, p.flt,
   up.projectManager) 
from UserProjectAssociation up left join up.project p 
where up.user.id = :userId and up.project.projectState != 'ARCHIVED' 
group by p.projectId

to retrieve projects for user. 为用户检索项目。 Projects are stored in one table, users in the other and UserProjectAssociation is a joining table with additional attribute - projectManager. 项目存储在一个表中,用户存储在另一个表中,而UserProjectAssociation是具有附加属性-projectManager的联接表。

The whole query works fine for H2 database, but on oracle I get this error: 整个查询适用于H2数据库,但是在oracle上我收到此错误:

ORA-00979: not a GROUP BY expression

What is a correct way to use GROUP BY for Oracle? 对Oracle使用GROUP BY的正确方法是什么?

Thanks! 谢谢!

The Problem. 问题。 ORA-00979 occurs when the GROUP BY clause does not contain all the expressions in the SELECT clause. 当GROUP BY子句不包含SELECT子句中的所有表达式时,发生ORA-00979。 Any SELECT expression that is not included in the GROUP function must be listed in the GROUP BY clause. 必须在GROUP BY子句中列出未包含在GROUP函数中的所有SELECT表达式。 These are AVG, COUNT, MAX, MIN, SUM, STDDEV, and VARIANCE. 它们是AVG,COUNT,MAX,MIN,SUM,STDDEV和VARIANCE。

see: https://www.tekstream.com/resources/ora-00979-not-a-group-by-expression/ 请参阅: https//www.tekstream.com/resources/ora-00979-not-a-group-by-expression/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM