2013-04-18 54 views
0

我在grails查询时出错。 我有类用户:参数#1没有设置错误

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]

为什么?

回答

1

看起来像currentUsernull

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

+0

是的,你的权利,业主是一个集合的问题。我解决了问题方式:User.withCriteria {拥有者{inList(“id”,[currentUser.id])}} .size() – 2013-04-19 03:01:36

相关问题