jpa 2 hibernate limit (max results) to a CriteriaQuery

Hugo picture Hugo · Sep 9, 2010 · Viewed 17.2k times · Source

maybe it's a silly question but I cannot find the answer in the docs: How can set a limit to the CriteriaQuery using JPA2?

Thanks

Answer

Mike Q picture Mike Q · Sep 9, 2010

A CriteriaQuery is not an executable Query. You need to create a TypedQuery first using EntityManager.createQuery(criteriaQuery). You can then set the max results of this and execute it.