如何为休眠查询设置限制 [英] How to set limit for a hibernate query

查看:90
本文介绍了如何为休眠查询设置限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为该hql查询设置限制?当我在查询中添加limit关键字时,会引发错误.

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);

推荐答案

调用查询时,请添加以下内容:

When you call your query add the following:

.setFirstResult(firstResult).setMaxResults(limit);

更新

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

如果您使用entityManager,它可能类似于:

If you use entityManager, it can be like:

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

这篇关于如何为休眠查询设置限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆