According to the latest GORM documentation, the count() method of CriteriaBuilder should return "The result count".
I find this not to be true when a projection is used in the CriteriaBuilder; then count() seems to return the total number of instances in the class.
For example, in my test application this code
def c = gtest01.TestA.createCriteria()
c.list {
projections {
groupProperty 'grouping'
count()
}
}.each { t ->
println "t $t"
}
prints 8 lines, as expected:
t [1, 12]
t [2, 16]
t [3, 9]
t [4, 18]
t [5, 5]
t [6, 20]
t [7, 13]
t [8, 7]
whereas this code
c = gtest01.TestA.createCriteria()
c.count {
projections {
groupProperty 'grouping'
count()
}
}.each { t ->
println "t $t"
}
prints
t 100
which is the total number of instances of TestA.
It seems to me either the documentation is wrong or the count() code is wrong. I'd like the problem to be with the code, since I can always get the total number of instances of the class with a call to gtest01.TestA.count()