2010-12-09 73 views

回答

6

this問題重複 「jpa 2 hibernate limit (max results) to a CriteriaQuery

甲CriteriaQuery中不是可執行 查詢。您需要首先使用 EntityManager.createQuery(criteriaQuery)創建TypedQuery 。 然後,您可以設置最大結果 並執行它。

+0

感謝。我曾經搜查過,但這個問題沒有出現在「分頁」的結果中。 – 2010-12-09 11:25:17

1

是,與實體管理器的使用,並通過一個標準的查詢作爲參數:

List<?> results = em.createQuery(criteria).setFirstResult(offset).setMaxResults(5).getResultList();