title: Hibernate: How to get only result objects whose count value are greater than a threshold
body: <p>This is my query_string. It delivers all persons including count(persAccsBOs). This string works.</p>
  
  <pre><code>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";
  </code></pre>
  
  <p>Now i want to get only persons whose count(persAccsBOs) is greater than a threshold. This doesnt work:</p>
  
  <pre><code>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) &gt;=  :threshold"
  + " group by pers";
  </code></pre>
  
  <p>I get the error message:</p>
  
  <blockquote>
    <p>14:55:27.121 [main] DEBUG
    org.hibernate.engine.jdbc.spi.SqlExceptionHelper 139 logExceptions -
    could not extract ResultSet [n/a] java.sql.SQLException: Invalid use
    of group function</p>
  </blockquote>
  
  <p>Can you help me with that?</p>