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

查询如下:



而且,域看起来像这样:

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

10-07 12:26
查看更多