How to set limit for a hibernate query

房东的猫 提交于 2019-12-04 03:26:04

When you call your query 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 use entityManager, it can be like:

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

You can use two method of Query object.

setFirstResult()

setMaxResults()

but you can not use it in HQL because limit is database vendor dependent so hibernate doesn't allow it through hql query

Vu Ruby

Limit was never a supported clause in HQL. You are meant to use setMaxResults().

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!