[英]Is there a “SELECT 1” in JPQL?
Is there some equivalent of "SELECT 1" or "SELECT 1 FROM DUAL" for JPQL? JPQL是否有一些等效的“SELECT 1”或“SELECT 1 FROM DUAL”? Like a simple test query.
就像一个简单的测试查询。
Yes, there is getResultList, which returns query results as an untyped List. 是的,有getResultList,它将查询结果作为无类型List返回。 And you can use setMaxResults, limiting it to 1:
您可以使用setMaxResults,将其限制为1:
query.setMaxResults(1).getResultList();
Or else you can say the following which returns a single untyped result: 或者你可以说以下返回一个无类型的结果:
query.getSingleResult()
The EntityManager API also allows creation of native queries, which may be your simplest approach: EntityManager API还允许创建本机查询,这可能是您最简单的方法:
entityManager.createNativeQuery("select 1 from sometable").getSingleResult();
For details, see http://docs.oracle.com/javaee/6/api/javax/persistence/Query.html . 有关详细信息,请参阅http://docs.oracle.com/javaee/6/api/javax/persistence/Query.html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.