如何通过使用JPA本机查询获取单个对象。我做了一些研究,但所有答案都是使用“getSingleResult”,但是它没有返回我想要的结果。例如,如果我想要在我的数据库中获取表的计数并将其提取到整数中,我应该怎么做。JPA本机查询获取单个对象
下面这段代码演示了如何通过使用Sessison冬眠得到这样的:
int check = Integer.parseInt((String) sessionF.createSQLQuery("select to_char(count(*)) as count from user_tables where table_name upper('TEST')").uniqueResult());
什么,我希望能在精JPA:
int check = Integer.parseInt((String) getEntityManager().createNativeQuery("select to_char(count(*)) as count from user_tables where table_name upper('TEST')").getSingleResult());
显然,代码不会返回什么我想要。因此,请帮助我解决这个问题。谢谢 !
这似乎是一个查询,您可以使用JPQL ... –