Need help creating JPA criteria query
I'm building my first Java EE web application using Glassfish and JSF. I'm fairly new to the criteria query and I have a query I need to perform but the javaee6 tutorial seems a little thin on examples. Anyway, I'm having a hard time creating the query. Goal: I want to pull the company with the most documents stored. Companies have a OneToMany relationship with Documents. Documents has a ManyToOne relationship with several tables, the "usertype" column distinguishes them. MySQL query: SELECT USERID, COUNT(USERID) AS CNT FROM DOCUMENTS WHERE USERTYPE="COMPANY" GROUP BY USERID ORDER BY CNT DESC