views:

59

answers:

2

I can write:

def c = Transaction.createCriteria() 
def transactions = c.list {
    projections {
        groupProperty("product")
        countDistinct("id")
    }
    maxResults(pageBlock)
    firstResult(pageIndex)
}

But can't write this:

def transactions = Transaction.createCriteria() .list {
    projections {
        groupProperty("product")
        countDistinct("id")
    }
    maxResults(pageBlock)
    firstResult(pageIndex)
}

Why is this? Why is the variable c required for holding the criteria?

+1  A: 

try using another name, not "transaction" and see if you get the desired results.

i took your code, and just changed the name of the objects and it works fine

Aaron Saunders
A: 

Your second example should work as Aaron pointed out. Sometimes I found when there are no results from the DB then you get errors so maybe it's that.

list() is the default by the way, so if you really want to shorten it, you can even do this:

def transactions = Transaction.createCriteria() {
Fletch