Home grails gorm critieria builder count returns incorrect value?
Reply: 0

grails gorm critieria builder count returns incorrect value?

user1228
1#
user1228 Published in June 19, 2018, 2:41 pm

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()

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.478051 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO