I am using oracle db.
To summarize my options (correct me if I’m wrong) I can:
- Make it as a subquery (in native sql only, as hibernate criteria API does not allow to use subselect in the
from
clause):
select count(*) as totalNumber
from (select distinct u.first_name, u.last_name, u.age from users u)
- Using blaze persistence:
CriteriaBuilder<String> cb = cbf.create(em, Long.class)
.from(User.class, "user")
.select("FUNCTION('COUNT_TUPLE', 'DISTINCT', u.firstName, u.lastName, u.age)");
- Using my first appoach
count(*) over()
(hibernate with native sql):
select
count(*) OVER () as totalRecords
from users u
group by
u.first_name,
u.last_name,
u.age
order by u.age DESC
OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY;
- I am not able to accomplish that using native hibernate criteria API without help from additional libraries, like blaze (considering I am using hibernate criteria and oracle db) - but can be done with JPA Criteria
Am I right ?