2012-04-20 112 views
0

我在我的hibernate创建条件查询中对数字字段求和。我需要另一列 - 从输出resultlist域类seriesType,但现在如果我添加术语property('seriesType')中的突起随着grouProperty()行我得到一个异常说not a group by clause could not execute query在grails中使用HibernateCriteriaBuilder从createCriteria中提取所有字段

不知道我怎样才能得到这里与结果 其他两个沿着场是我的标准

dataMap = BehaviorProfile.createCriteria().list { 
        globalUser{ 
         eq('id',empid2) 
        } 

        projections{ 
         sum('frequency', 'tfreq') 
         groupProperty('dayofweek') 
        // if I add property('seriesType') here the criteria throws an exception 
        } 

       } 

回答

1

您需要添加groupProperty('seriesType')property('seriesType')。当你通过一些属性A进行分组并且使用聚合函数 - 在你的情况下求和 - 你不能仅仅输出一些其他属性B,因为在你的B preoperty中也可能有很多值。

例如,在您的dayofweek = 2聚合组中,总数为150,并且有三种可能的seriesTypes - siereA,serieB和serieC。这就是为什么您需要:只按dayofweek分组或按照seriesTypes将group添加到您的查询。