2014-03-06 46 views
0

這是我的query_string。它提供所有人包括計數(persAccsBOs)。該字符串有效。休眠:如何僅獲得計數值大於閾值的結果對象

hql_query_string = "" 
+ "select distinct pers, count(persAccsBOs) as anzBo from Person as pers" 
+ " inner join pers.personenAttribute as persAttr inner join persAttr.pa_pk.attribut as pAttr" 
+ " inner join pers.accounts as persAccs" 
+ " inner join persAccs.berechtigungsobjekte as persAccsBOs" 
+ " where pAttr.name= :attrName" 
+ " and persAttr.wert= :attrValue" 
+ " group by pers"; 

現在我只想得到計數(persAccsBOs)大於閾值的人。這不工作:

hql_query_string = "" 
+ "select distinct pers, count(persAccsBOs) as anzBo from Person as pers" 
+ " inner join pers.personenAttribute as persAttr inner join persAttr.pa_pk.attribut as pAttr" 
+ " inner join pers.accounts as persAccs" 
+ " inner join persAccs.berechtigungsobjekte as persAccsBOs" 
+ " where pAttr.name= :attrName" 
+ " and persAttr.wert= :attrValue" 
+ " and count(persAccsBOs) >= :threshold" 
+ " group by pers"; 

我得到的錯誤信息:

14:55:27.121 [主] DEBUG org.hibernate.engine.jdbc.spi.SqlExceptionHelper 139 logExceptions - 不能提取ResultSet [n/a] java.sql.SQLException:無效的使用 組功能

你能幫我嗎?

回答

2

亞歷山大,

我相信這將工作:

上聚集的領域
hql_query_string = "" 
+ "select distinct pers, count(persAccsBOs) as anzBo from Person as pers" 
+ " inner join pers.personenAttribute as persAttr inner join persAttr.pa_pk.attribut as pAttr" 
+ " inner join pers.accounts as persAccs" 
+ " inner join persAccs.berechtigungsobjekte as persAccsBOs" 
+ " where pAttr.name= :attrName" 
+ " and persAttr.wert= :attrValue" 
+ " group by pers" 
+ " having count(persAccsBOs) >= :threshold"; 

條件必須與having子句進行,而不是在where子句中。

+0

Thx psud,作品! –