How to set a limit for a sleeping request

How to set a limit on this hql request? When I add the limit keyword to the query, an error occurs.

@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); 
+6
source share
3 answers

When you invoke your request, add the following:

 .setFirstResult(firstResult).setMaxResults(limit); 

UPDATE

Docs:
http://docs.jboss.org/hibernate/orm/3.6/javadocs/org/hibernate/Query.html#setMaxResults(int)

If you are using entityManager, it could be like:

 entityManager.createQuery("yourQuery").setFirstResult(0).setMaxResults(5); 
+13
source

You can use two methods of the Query object.

setFirstResult ()

setMaxResults ()

but you cannot use it in HQL because the restriction depends on the database provider, so hibernate does not allow it through an hql request

+3
source

The limit was never maintained in HQL. You must use setMaxResults ().

0
source

Source: https://habr.com/ru/post/949791/


All Articles