I have following criteria method.
@Autowired
EntityManager entityManager;
public Long execCountQuery() {
final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
final CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
final Root<Order> companyRoot = criteriaQuery.from(Order.class);
criteriaQuery.select(criteriaBuilder.count(companyRoot));
return entityManager.createQuery(criteriaQuery).getSingleResult();
}
Unfortunately spring boot 3.2.1 generate count_big(does not exists) instead of count for H2 database. But spring boot 2.7.18 generate count. Is there any way to force to generate count instead of count_big?
I experienced the same problem after upgrading Spring Boot from 2.7 to 3.2. I also got exception InvalidDataAccessResourceUsageException: could not prepare statement Function "COUNT_BIG" not found
upon calling count()
.
Hibernate logs were showing this:
Hibernate:
select
count_big(*)
from
........
Then I set dialect like below and count_big()
was changed to count()
:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
Logs are showing this now:
Hibernate:
select
count(*)
........