How to set limit for a hibernate query
hql
Solution
When you call your query add the following:
.setFirstResult(firstResult).setMaxResults(limit);
`setFirstResult` is the (optional) offset, `setMaxResults` is the limit.
UPDATE
Docs: http://docs.jboss.org/hibernate/orm/3.6/javadocs/org/hibernate/Query.html#setMaxResults(int)
If you use entityManager, it can be like:
entityManager.createQuery("yourQuery").setFirstResult(0).setMaxResults(5);
Problem
How can I set a limit to this hql query? When I add the limit keyword in the query, an error is thrown. ``` @Query("from voucher v where v.voucherType.typeDescription = :typeDescription and v.denomination = :denomination") public List<Voucher> findByVoucherTypeAndDenomination(@Param("typeDescription") String typeDescription,@Param("denomination") BigDecimal denomination); ```