Change to using HQL. Complete group by and having.