2

My Question is exactly like Grails Projections not returning all properties and not grouped

I have a following criteria

def sharedDocumentsInstanceList SharedDocuments.createCriteria().list(params){
   createAlias('receiver', 'r')
   createAlias('author', 'a')
   eq("r.id",session.uid)  
   projections{
      groupProperty("a.id")
      property("a.firstName","firstName")
      property("a.lastName","lastName")
      property("a.emailAddress","email")
   }
}

Where sharedDocuments is defined as follows

class SharedDocuments {
   Users author
   Users receiver
   Documents file
}

What I have seen is that sharedDocumentsInstanceList always has only the last property mentioned in the projection. I can use the same query in "withCriteria" but I seem to loose the groovy goodness of automatic pagination with it because withCriteria does not return paged pagedresultlist!

Community
  • 1
  • 1
Sap
  • 5,197
  • 8
  • 59
  • 101

2 Answers2

2

For the sake of those still having this issue; Remove the provided params object on the list method. So the criteria query above becomes:

def sharedDocumentsInstanceList = SharedDocuments.createCriteria().list {
    createAlias('receiver', 'r')
    createAlias('author', 'a')
    eq("r.id",session.uid)  
    projections {
        groupProperty("a.id")
        property("a.firstName","firstName")
        property("a.lastName","lastName")
        property("a.emailAddress","email")
    }
    maxResults(params.max)
    firstResult(params.offset)
    order(params.sort, params.order)
}
jgithaiga
  • 134
  • 6
  • 2
    You can add `resultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP)` if you prefer familiar grails-like query result. – jgithaiga Oct 30 '13 at 13:52
0
    projections{                
        author {
           groupProperty("id")
           property("firstName","firstName")
           property("lastName","lastName")
           property("emailAddress","email")
        }
    }

Would using the above approach yield different results? Just a thought...

David Brown
  • 3,021
  • 3
  • 26
  • 46
  • Nope, I got rid of the count and wrote the criteria as you suggested but it still only prints the emailAddress. – Sap Mar 07 '13 at 05:55