开发者

How do I limit JPQ output?

开发者 https://www.devze.com 2022-12-28 09:55 出处:网络
I need to limit number of entities returned by a query to some certain value inside a JPA query (through JPQL). Particularly:

I need to limit number of entities returned by a query to some certain value inside a JPA query (through JPQL). Particularly:

select m from Manual m //constraint

e.g. in sql (mysql syntax) I would do it like:

select * 开发者_如何学编程from Manual limit 1

The only solution that comes up is simply to get all entities and then choose first one, which is out of the question. Any ideas?


To do that I may limit Query instance, as follows:

em.createQuery("select m from Manual m").setMaxResults(1).getSingleResult()
0

精彩评论

暂无评论...
验证码 换一张
取 消