Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将查询返回的实体数量限制为 JPA 查询中的某个特定值(通过 JPQL)。特别:
select m from Manual m //constraint
例如在 sql (mysql 语法) 中我会这样做:
select * from Manual limit 1
出现的唯一解决方案是简单地获取所有实体,然后选择第一个,这是不可能的。有任何想法吗?
为此,我可能会限制 Query 实例,如下所示:
em.createQuery("select m from Manual m").setMaxResults(1).getSingleResult()