Search code examples
grailsgrails-orm

Parameter #1 is not set error


I got an error with grails query. I had class User:

class User {
String username
String passwordHash

static hasMany = [roles: Role, permissions: String, clients: User, owners: User]
}

When i do query:

def addClient() {
    def principal = SecurityUtils.subject?.principal
    User currentUser = User.findByUsername(principal);
    if (request.method == 'GET') {
        User user = new User()
        [client: currentUser, clientCount: User.countByOwners(currentUser)]
    }
}

Grails say that:

Parameter "#1" is not set; SQL statement: select count(*) as y0_ from user this_ where this_.id=? [90012-164]

Why?


Solution

  • Looks like currentUser is null.

    BTW, I wonder, why you count by owners, but specify a user as the owners? According to your hasMany definition, owners is a collection.