我想在 Grails 中创建以下语句HibernateCriteriaBuilder
:
SELECT * FROM person p
JOIN person_authority pa ON p.id=pa.person_id
JOIN authority a ON pa.authority_id=a.id
WHERE a.authority IN ('ROLE_ADMIN');
person_authority
是连接表。
更新:
我的Person
课是:
class Person {
transient springSecurityService
Date dateCreated
Date lastLogin
String username
String password
String email;
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static constraints = {
username blank: false, unique: true
email blank:false, unique: true, email: true
password blank: false
lastLogin nullable:true
}
static mapping = {
hasMany authority:Authority;
password column: '`password`'
}
//Set<Authority> getAuthorities() {
// PersonAuthority.findAllByPerson(this).collect { it.authority } as Set
//}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}
public static def query(Map params = [:]){
def rows = withCriteria(max:params.max,offset:params.offset){
if(params.authorities){
authorities{
'in'('authority', params.authorities)
}
}
order(params.column?:"id",params.order?:"asc")
if(params.id){
idEq (params.id as Long);
}
if(params.username){
ilike "username","%"+params.username+"%"
}
if(params.email){
ilike "email","%"+params.email+"%"
}
if(params.accountLocked){
eq "accountLocked",Boolean.valueOf(params.accountLocked)
}
if(params.enabled){
eq "enabled",Boolean.valueOf(params.enabled)
}
if(params.passwordExpired){
eq "passwordExpired",Boolean.valueOf(params.passwordExpired)
}
}
return rows;
}
}
我要建立的标准是在方法查询中。当我尝试执行它时,我得到groovy.lang.MissingMethodException: No signature of method: grails.orm.HibernateCriteriaBuilder.authorities() is applicable for argument types ...