PagedResultList .size() and .getTotalCount() return different values in grails gorm -
i have following code
pagedresultlist res = myservice.getpage(paginateparams, ...) println res.size() // returns 2 println res.gettotalcount() // returns 1
getpage looks like:
def criteria = mydomain.createcriteria() criteria.list(max: paginateparams.max, offset: paginateparams.offset) { // max 10, offset 0, sortby updatedat , sortorder desc eq('org', org) order(paginateparams.sortby, paginateparams.sortorder) }
why 2 method return different values? documentation doesn't explain difference, mention gettotalcount number of records
currently on grails 2.4.5
edits:
println on res prints out:
res: [ com.<hidden>.mydomain: 41679f98-a7c5-4193-bba8-601725007c1a, com.<hidden>.mydomain: 41679f98-a7c5-4193-bba8-601725007c1a]
yes, res has single object twice - that's bug i'm trying fix. how know that? have primary key on mydomain's id, , when inspect database, it's showing 1 record particular org (see criteria)
edit 2: found comment (http://docs.grails.org/2.4.5/ref/domain%20classes/createcriteria.html)
listdistinct if subqueries or associations used, 1 may end same row multiple times in result set. in hibernate 1 "criteriaspecification.distinct_root_entity". in grails 1 can using method.
which, if understand correctly, way of saying "list" method doesn't work in scenario, use listdistinct instead go on warn:
the listdistinct() method not work pagination options maxresult , firstresult. if need distinct results pagination, recommend use hql. can find out more information blog post.
however, blog post dead link.
related: gorm createcriteria , list not return same results : can do?
not related actual problem after question edited quote seems useful
generally pagedresultlist
.size()
perform size() on resultlist property (in-memory object represent database record), while.gettotalcount()
count query against database. if 2 value didn't match list may contain duplicate.
Comments
Post a Comment