Skip to content

Commit

Permalink
Fix getTotalCount() with Hibernate for sorting parameters
Browse files Browse the repository at this point in the history
Don't have sorting in the generated query. Otherwise, depending on the
database and its strictness configuration, the query might fail.

The `PagedResultSpec` in `grails-datastore-gorm-tck` covers this.
  • Loading branch information
darxriggs committed Oct 1, 2023
1 parent d20a687 commit 6b16e83
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public int getTotalCount() {
if (totalCount == Integer.MIN_VALUE) {
totalCount = hibernateTemplate.execute(new GrailsHibernateTemplate.HibernateCallback<Integer>() {
public Integer doInHibernate(Session session) throws HibernateException, SQLException {
final CriteriaQuery finalQuery = criteriaQuery.select(criteriaBuilder.count(queryRoot)).distinct(true);
final CriteriaQuery finalQuery = criteriaQuery.select(criteriaBuilder.count(queryRoot)).distinct(true).orderBy();
final Query query = session.createQuery(finalQuery);
hibernateTemplate.applySettings(query);
return ((Number)query.uniqueResult()).intValue();
Expand Down

0 comments on commit 6b16e83

Please sign in to comment.