以下hql_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='UID_Department'"
+ " and persAttr.wert='Sales (10100200)'"
+ " group by pers";
现在,我想要实现和失败的是获得所有anzBo的平均值。我尝试了以下query_string:
query_string = ""
+ "select avg(anzBo) from "
+ " (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='UID_Department'"
+ " and persAttr.wert='Sales (10100200)'"
+ " group by pers)";
我收到错误消息:
意外令牌:选择第1行第25列附近[select avg(anzBo) 来自select distinct pers ...
我希望你知道我想做什么。你能帮我组建正确的hql_string吗?
更新:
如果我试试这个:
query_string = ""
+ "select distinct pers, count(persAccsBOs) as anzBo, avg(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='UID_Department'"
+ " and persAttr.wert='Sales (10100200)'"
+ " group by pers";
我将得到一个java.lang.NullPointerException。