2013-04-18 57 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

相關問題