I’m creating a dynamic query in a Spring Boot (3.3) app, with Hibernate, Postgresql behind…
This is a simplified pseudocode version:
CriteriaQuery<Long> counter = ....;
CriteriaBuilder criteriaBuilder = .... ;
Root<?> root = .... ;
counter.select(criteriaBuilder.count(root));
Hibernate logs show that the count is converted in an SQL ‘count(id)’ query. When I changed it to ‘count ()’ I had a noticeable improvement in performance. So I’m wondering how I could do a count() instead of count (id) using JPA?