grails-org.hibernate.QueryException(无法解析属性)
我正在尝试从当前用户处获取特定租金的列表 控制器中的代码:grails-org.hibernate.QueryException(无法解析属性),grails,hql,Grails,Hql,我正在尝试从当前用户处获取特定租金的列表 控制器中的代码: def index() { if (isLoggedIn()) { String username = getPrincipal().username def accountInstance = Account.findByUsername(username) def rentalInstanceList = Rental.findAll("from Rental as r where r.account_i
def index() {
if (isLoggedIn()) {
String username = getPrincipal().username
def accountInstance = Account.findByUsername(username)
def rentalInstanceList = Rental.findAll("from Rental as r where r.account_id=:accountid", [accountid: accountInstance.id])
}
}
帐户id是外键
运行后,我得到错误信息:
could not resolve property: account_id of: ers.Rental
我做错了什么?findAll不限于调用类的实例,所以我使用executeQuery 通常,在HQL中,必须使用域类中定义的字段名。因此,您的查询应该如下所示:
def list = Rental.findAll("from Rental where accountId=:accountid", [accountid: accountInstance.id])
或
甚至
def list = Rental.findAllByAccount getPrincipal()
如果
getPrincipal()
的返回类型具有id
字段。我们可以查看您的租赁域类吗?
def list = Rental.findAllByAccount getPrincipal()