I can write:
def c = Transaction.createCr开发者_运维知识库iteria()
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?
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
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() {
精彩评论