0

我收到 grails 查询错误。我有班级用户:

class User {
String username
String passwordHash

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

当我查询时:

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 说:

参数“#1”未设置;SQL 语句:select count(*) as y0_ from user this_ where this_.id=? [90012-164]

为什么?

4

1 回答 1

1

看起来currentUsernull

顺便说一句,我想知道,为什么您按所有者计算,但将用户指定为所有者?根据你的hasMany定义,owners是一个集合。

于 2013-04-18T08:17:12.313 回答