Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 30a79bb

Browse files
committed
Fix getTotalCount() with Hibernate for sorting parameters
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.
1 parent 3a0fc2a commit 30a79bb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/query/PagedResultList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public int getTotalCount() {
5858
if (totalCount == Integer.MIN_VALUE) {
5959
totalCount = hibernateTemplate.execute(new GrailsHibernateTemplate.HibernateCallback<Integer>() {
6060
public Integer doInHibernate(Session session) throws HibernateException, SQLException {
61-
final CriteriaQuery finalQuery = criteriaQuery.select(criteriaBuilder.count(queryRoot)).distinct(true);
61+
final CriteriaQuery finalQuery = criteriaQuery.select(criteriaBuilder.count(queryRoot)).distinct(true).orderBy();
6262
final Query query = session.createQuery(finalQuery);
6363
hibernateTemplate.applySettings(query);
6464
return ((Number)query.uniqueResult()).intValue();

0 commit comments

Comments
 (0)