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

标签 grails gorm

我正在尝试针对其进行查询的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/

相关文章:

grails - 在Grails下运行的Servlet

Grails cobertura 插件正在 BuildConfig.groovy 上进行代码覆盖

hibernate - Gorm返回值类型

grails - GSP表单参数附加到参数-需要覆盖

Grails 配置文件返回空对象而不是字符串

grails - 注销后使用Spring Security将用户重定向到自定义页面吗?

hibernate - Grails hasMany关联检查

grails - Grails:使用分配器的id生成器,如果未分配,则回退到序列

grails - 从迁移中生成SQL,而不需要全部操作

spring - GORM无法从JAR引导