鉴于以下领域:
class UserRole implements Serializable {
User user
Role role
}
class User {
Set<Role> getRoles() {
UserRole.findAllByUser(this).collect { it.role } as Set
}
}
class Role {
Set<User> getUsers() {
UserRole.findAllByRole(this).collect { it.user } as Set
}
I can t figure out how to build the criteria to find all the users with a given role. I tried the following:
def crit = User.createCriteria()
def results = crit.list {
roles {
eq( authority , ROLE_ADMIN )
}
}
然而,它说,它无法在使用者中找到财产角色。 因此,我需要一个标准,因为用户将有更多的财产被搜寻到如此充满活力的寻找者为这种情况而赢得的拖车。