gpt4 book ai didi

grails - 为什么此Grails(GORM)查询无效?

转载 作者:行者123 更新时间:2023-12-02 15:09:14 26 4
gpt4 key购买 nike

我正在尝试针对其进行查询的Grails中具有以下域模型,但是失败,说这是无效的查询。

查询如下:

  StringBuilder queryBuf = new StringBuilder();
queryBuf.append("select rr.role from ReportRole rr ");
def newroles = ReportRole.findAll(queryBuf)


而且,域看起来像这样:
package auth

import java.util.Date
import auth.Report
import auth.Role

class ReportRole {
Long id
Report report
Role role
Date dateCreated
Date lastUpdated
Person createdBy

static mapping = {
table 'CIT_RM_Report_Role'
version false
role joinTable:[name:'AU_ROLE_DESCR', key:'role_id', column:'id']
columns {
id column:'report_role_id'
report column:'report_id'
createdBy column:'created_by'
dateCreated column:'create_date'
lastUpdated column:'last_updated'

}
}
}
package auth;
class Role {
static hasMany = [people: Person]
Long id;
String authority;
String description;
static mapping = {
table 'AU_ROLE_DESCR'
people joinTable:[name:'AU_PERSON_ROLE', key:'AUTHORITY_ID', column:'PERSON_ID']
version false;
}
}

谁能告诉我为什么这是无效的。我有一些类似的域,像这样的查询将起作用。

最佳答案

我想findAll被限制为只能返回域列表,而不是任何特定的关联/元素。您可以更好地使用executeQuery来实现您想要的目标:

ReportRole.executeQuery("select rr.role from ReportRole rr")

关于grails - 为什么此Grails(GORM)查询无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19429034/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com