JPA Criteria Group By
<p>I have got the following problem, maybe somebody can help me.</p>

<p>I wrote a SQL query:</p>

<pre><code>SELECT v.bezeichnung, count(*) as total  
FROM veranstaltung v 
    JOIN  auffuehrung a  ON  v.id = a.veranstaltung_id
    JOIN  platz p  ON p.auffuehrung_id = a.id
    JOIN   transaktion t ON t.id = p.transaktion_id  
WHERE t.status = 2 AND (a.datumuhrzeit + 30 DAY) &gt;= CURRENT_DATE  
GROUP BY v.bezeichnung  
ORDER BY total DESC
</code></pre>

<p>I have to implement it in JPA but everything works except GROUP BY... it can't be grouped..</p>

<pre><code>CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();  
CriteriaQuery&lt;Veranstaltung&gt; query = builder.createQuery(Veranstaltung.class);  
Root&lt;Veranstaltung&gt; rootVeranstaltung = query.from(Veranstaltung.class);                        query.where(builder.equal(rootVeranstaltung.join("auffuehrungen").join("plaetze").join("transaktion").&lt;Transaktionsstatus&gt;get("status"), Transaktionsstatus.BUCHUNG));  
query.groupBy(rootVeranstaltung);  
List&lt;Veranstaltung&gt; result = this.entityManager.createQuery(query).getResultList();  
return list;
</code></pre>

<p>I haven't finished the code yet, e.g. the COUNT..
should i write <code>COUNT</code> already before <code>GROUP BY</code> or would it work without <code>COUNT</code>?</p>
