我正在使用 JPA 的 distinct 投影来获取一些数据:
select distinct o.f1, o.f2, o.f3 from SomeEntity o where ...
使用setFirstResult和setMaxResults分页数据的操作是正常的。
但是我需要在不获取所有行的情况下计算总行数。我尝试过:
select count(distinct o.f1, o.f2, o.f3) from SomeEntity o where ...
这种方法不起作用(至少在 EclipseLink 中是这样),而且 JPA 规范似乎也不允许这样做。有其他的方法吗?我不想编写 SQL 查询来实现这个功能。