title: PagedResultList .size() and .getTotalCount() return different values in grails gorm
body: <p>I have the following code    </p>
  
  <pre><code>PagedResultList res = myService.getPage(paginateParams, ...)
  println res.size() // returns 2
  println res.getTotalCount() // returns 1
  </code></pre>
  
  <p>getPage looks like:</p>
  
  <pre><code>def criteria = MyDomain.createCriteria()
  criteria.list(max: paginateParams.max, offset: paginateParams.offset) { // max is 10, offset is 0, sortBy is updatedAt and sortOrder is desc
      eq('org', org)
      order(paginateParams.sortBy, paginateParams.sortOrder)
  }
  </code></pre>
  
  <p>why do the two method return different values? The documentation doesn't explain the difference, but does mention that getTotalCount is for number of records</p>
  
  <p>currently on grails 2.4.5</p>
  
  <p>edits:</p>
  
  <p>println on res prints out:</p>
  
  <pre><code>res: [
  com.&lt;hidden&gt;.MyDomain: 41679f98-a7c5-4193-bba8-601725007c1a, 
  com.&lt;hidden&gt;.MyDomain: 41679f98-a7c5-4193-bba8-601725007c1a]
  </code></pre>
  
  <p>Yes, res has a SINGLE object twice - that's the bug I'm trying to fix.  How do I know that? I  have an primary key on MyDomain's ID, and when I inspect the database, it's also showing one record for this particular org (see my criteria)</p>
  
  <p>edit 2:  I found this comment (<a href="http://docs.grails.org/2.4.5/ref/Domain%20Classes/createCriteria.html" rel="nofollow noreferrer">http://docs.grails.org/2.4.5/ref/Domain%20Classes/createCriteria.html</a>)</p>
  
  <blockquote>
    <p>listDistinct  If subqueries or associations are used, one may end up
    with the same row multiple times in the result set. In Hibernate one
    would do a "CriteriaSpecification.DISTINCT_ROOT_ENTITY". In Grails one
    can do it by just using this method.</p>
  </blockquote>
  
  <p>Which, if I understand correctly, is their way of saying "list" method doesn't work in this scenario, use listDistinct instead but then they go on to warn:</p>
  
  <blockquote>
    <p>The listDistinct() method does not work well with the pagination
    options maxResult and firstResult. If you need distinct results with
    pagination, we currently recommend that you use HQL. You can find out
    more information from this blog post.</p>
  </blockquote>
  
  <p>However, the blog post is a dead link.</p>
  
  <p>Related: <a href="https://stackoverflow.com/questions/3905476/gorm-createcriteria-and-list-do-not-return-the-same-results-what-can-i-do">GORM createCriteria and list do not return the same results : what can I do?</a></p>