Reputation: 2748
I have the following domain models in Grails I am trying to run a query against, but it is failing, saying it is an invalid query.
The query looks like:
StringBuilder queryBuf = new StringBuilder(); queryBuf.append("select rr.role from ReportRole rr "); def newroles = ReportRole.findAll(queryBuf)
And, the domains look like this:
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;
}
}
Can anyone tell me why this is invalid. I have some similar domains where a query like this will work.
Upvotes: 0
Views: 449
Reputation: 50275
I suppose findAll
is restricted to get back with a list of domain instead of any association/element in particular. You can better use executeQuery
to achieve what you seek:
ReportRole.executeQuery("select rr.role from ReportRole rr")
Upvotes: 2