borinquenkid opened a new pull request, #16731:
URL: https://github.com/apache/grails-core/pull/16731
## Summary
`count()` on a `DetachedCriteria` or a criteria builder that also has an
`order` threw on H2:
```
Column "CTE1_0.AMOUNT" must be in the GROUP BY list
select count(cte1_0.id) from criteria_test_entity cte1_0 order by
cte1_0.amount
```
A count has one row whatever the order, and an ORDER BY on a column that is
not aggregated fails on H2 and most other databases. Only the paged-list total
escaped it, because `HibernatePagedResultList` clears the orders before it
counts.
`JpaCriteriaQueryCreator` now leaves the criteria's orders out when every
projection of the query is a count, which is how `count()` and
`countDistinct()` set the query up. A query that groups and counts keeps its
orders, so `projections { groupProperty(...); count(...) }` with an `order` is
unchanged.
Found while reviewing #16696 (jdaugherty's comment on `assignOrderBy`): that
PR adds order handlers, whose orders run into the same count path, and its docs
currently tell every handler to return `null` for a count. With this fix the
framework drops the orders instead, so that advice can go.
## Verification
- New feature in `HibernateCriteriaBuilderDirectSpec`:
`DetachedCriteria.count()` with an order, with a criterion and an order,
`rowCount()` with an order through the builder, `createCriteria().count {
order(...) }`, and the order still applying to `list()`. It failed with the
error above before the fix.
- `:grails-data-hibernate7-core:test`: 3,794 tests, 0 failures, 59 skipped.
- `checkstyleMain` and `codenarcTest` for the module: clean.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]