Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Duplicate
-
Affects Version/s: 1.0
-
Fix Version/s: 1.2-M4
-
Component/s: None
-
Labels:None
Description
I was trying to pass in pagination and sorting parameters to the list method and noticed it was throwing SQL exception from HSQL due to the generated query containing a count
and an order by clause.
It's caused by these lines in the builder (172-180), which adds a count
in order to set the totalCount property on the result set:
} else if(paginationEnabledList) { GrailsHibernateUtil.populateArgumentsForCriteria(this.criteria, (Map)args[0]); PagedResultList pagedRes = new PagedResultList(this.criteria.list()); this.criteria.setFirstResult(0); this.criteria.setMaxResults(Integer.MAX_VALUE); this.criteria.setProjection(Projections.rowCount()); int totalCount = ((Integer)this.criteria.uniqueResult()).intValue(); pagedRes.setTotalCount(totalCount); result = pagedRes; }
a simple fix is to remove the ordering clause before calling uniqueResult, however there is no method to do this so I tested using reflection and it works well:
try { Field ordering = this.criteria.getClass().getDeclaredField("orderEntries"); ordering.setAccessible(true); ordering.set(this.criteria, new ArrayList()); } catch (Exception e) { //Ignore }
However this is not a very 'nice' solution - should we raise an issue with Hibernate instead?
Issue Links
| This issue duplicates: | ||||
| GRAILS-2735 | Criteria.list() with paginate and sort order causes SQLException |
|
|
|
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits