如果我有一个按查询分组
Select e.field1, e.field2...
from Entity w
group by e.field1, e.field2...
如何计算不使用NativeQuery的行数? 我需要做这样的事情:
select count(*) from
(Select e.field1, e.field2...
from Entity w
group by e.field1, e.field2...)
有没有办法使用JPQL?
答案 0 :(得分:0)
JPQL不支持派生表,因此,最好的方法是运行本机SQL查询。
毕竟,there is a very good reason why both JPA and Hibernate offer support for SQL queries,你不同意吗?
答案 1 :(得分:0)
Select sum(count(*) - count(*) + 1)
from Entity e
group by e.field1, e.field2...
但不适用于postgres