HaroldHormaechea opened a new issue, #14339:
URL: https://github.com/apache/grails-core/issues/14339
_Tested both in 7.2.1& 8.1.0_
`grails.orm.PagedResultList` is a deprecated class which points to using
`org.grails.orm.hibernate.query.PagedResultList` instead.
When calling `BuildableCriteria#list`, the method
`grails.orm.HibernateCriteriaBuilder#createPagedResultList` builds a
`grails.orm.PagedResultList` which can not be casted to the new
`org.grails.orm.hibernate.query.PagedResultList`.
```java
/**
* A result list for Criteria list calls, which is aware of the totalCount
for
* the paged result.
*
* @author Siegfried Puchbauer
* @since 1.0
* @deprecated Use {@link org.grails.orm.hibernate.query.PagedResultList}
instead.
*/
@SuppressWarnings({"unchecked","rawtypes"})
@Deprecated
public class PagedResultList extends grails.gorm.PagedResultList
```
Casting to the parent of both classes `grails.gorm.PagedResultList` causes
another bug where if a caller asks for a page beyond the last, which has 0
elements in it, the method `grails.gorm.PagedResultList#initialize` finds a
null `query` and defaults to 0 total results, because all the constructors of
`grails.orm.PagedResultList` push a `null` query to the super constructor:
Constructors of `grails.orm.PagedResultList`:
```java
public PagedResultList(GrailsHibernateTemplate template, Criteria crit) {
super(null);
...
}
public PagedResultList(GrailsHibernateTemplate template, HibernateQuery
query) {
super(null);
...
}
```
Affected method:
```java
protected void initialize() {
if (totalCount == Integer.MIN_VALUE) {
if (query == null) {
totalCount = 0;
} else {
Query newQuery = (Query)query.clone();
newQuery.projections().count();
Number result = (Number) newQuery.singleResult();
totalCount = result == null ? 0 : result.intValue();
}
}
}
```
--
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]