Hibernate Criteria does not support window functions. Check out Blaze Persistence which adds this to the JPA Criteria.
@beikov can tell you more since he’s the project author.
However, your SQL query is wrong anyway since you are counting without projecting the group, hence yo h won’t be able to know what group a count is associated with.