Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
grails-org.hibernate.QueryException(无法解析属性)_Grails_Hql - Fatal编程技术网

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()