This should work if you are using Oracle:
select u from User u where size(u.comments) = ( select max(count(c.id)) from User u2 inner join u2.comments c group by u2.id )
But MySQL and SQL Server do not support nested aggregate functions, max(count(c.id)) in this case. It is suggested to use a subquery, but with HQL you cannot have subqueries in the from clause. Therefore, I suggest you do it manually, i.e. Download all users:
select u, size(u.comments) from User u
and scroll through the list.
source share