jdaugherty commented on code in PR #16520:
URL: https://github.com/apache/grails-core/pull/16520#discussion_r4185964289
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/HibernateQuery.java:
##########
@@ -488,6 +488,12 @@ private HibernateQueryExecutor getHibernateQueryExecutor()
{
offset, max, lockResult, queryCache, fetchSize, timeout,
flushMode, readOnly, proxyHandler);
}
+ /** An executor that never pages, because max and offset do not apply to a
count. */
+ private HibernateQueryExecutor getCountQueryExecutor() {
Review Comment:
Commenting here because the call site isn't in the diff: the criteria
builder's `count {}` still pages. `CriteriaMethodInvoker` runs `count` as
`hibernateQuery.projections().count()` followed by
`hibernateQuery.singleResult()`, which uses the paging executor, so a
`firstResult` inside the closure skips the single count row:
```groovy
CountItem.createCriteria().count { firstResult(10) } //
null, expected 58
CountItem.createCriteria().count { maxResults(2); firstResult(10) } //
null, expected 58
CountItem.createCriteria().count { eq('itemGroup', 1); firstResult(5) } //
null, expected 10
```
(This uses the 58-row `CountItem` data from `DetachedCriteriaCountSpec`.)
Calling `hibernateQuery.countResults()` there instead returns 58, 58 and 10
locally. The criteria and count specs still pass, except
`CriteriaMethodInvokerSpec` "test invokeMethod handles count call", which mocks
`projections()`/`singleResult()` and would need updating. Could you include
that in this PR, with a `HibernateCriteriaBuilderSpec` case for `count` with
`firstResult`?
--
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]