|
I wrote a very simple criteria query on UserRole Domain Object(created by spring-security-core) and am baffled with sql output
def userRole=UserRole.withCriteria{
} The generate Sql doesn't create a join with user table and gives error as Unknown column 'usr1_.username' in 'where clause'. SQL Log: "select this_.role_id as role1_0_0_, this_.user_id as user2_0_0_ from user_role this_ where this_.role_id=? and usr1_.username=?" Am I missing something??? PS : UserRole the default generated Serializable Domain Class generated by spring-security-core. It is a mapping class Between User and Role Domain Class and has user and role as 2 fields. |
|
Hello Ravi, Do not understand the reason as well but maybe try this: def userRole=UserRole.withCriteria{ eq('role',Role.findByAuthority('ROLE_ADMIN')) user { eq("username","admin1") } } Thursday, March 1, 2012, 1:49:24 PM, you wrote:
-- Best regards, Michael Astreiko --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Michael, Thanks! I tried your solution but got exactly the same error. Between, when i started with grails (1.3.7), this looked as the most intuitive syntax to traverse the object hierarchy but it did not use to work. That is when i figured that this syntax is only valid for associations and createAlias is the way one can traverse the object hierarchy.
The SQL log for your suggestion: "select this_.role_id as role1_0_0_, this_.user_id as user2_0_0_ from user_role this_ where this_.role_id=? and usr1_.username=?"
On Thu, Mar 1, 2012 at 5:19 PM, michael astreiko [via Grails] <[hidden email]> wrote:
|
|
In reply to this post by michael astreiko
The cause for this behavior is UserRole has a compositeId and is serializable (id composite: ['role', 'user']). If I remove this, createAlias works fine.
It will be enlightening to know why? or if it is a bug, I can raise a JIRA.
On Thu, Mar 1, 2012 at 6:06 PM, Ravi Pratap <[hidden email]> wrote: Michael, Thanks! I tried your solution but got exactly the same error. Between, when i started with grails (1.3.7), this looked as the most intuitive syntax to traverse the object hierarchy but it did not use to work. That is when i figured that this syntax is only valid for associations and createAlias is the way one can traverse the object hierarchy. |
|
In reply to this post by Ravi Pratap
Hello Ravi, And what is content of yours UserRole domain? Thursday, March 1, 2012, 3:36:29 PM, you wrote:
-- Best regards, Michael Astreiko --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
it is the default generated by spring-security-core
class UserRole implements Serializable { User user Role role boolean equals(other) { if (!(other instanceof UserRole)) { return false } other.user?.id == user?.id && other.role?.id == role?.id } int hashCode() { def builder = new HashCodeBuilder() if (user) builder.append(user.id) if (role) builder.append(role.id) builder.toHashCode() } static UserRole get(long userId, long roleId) { find 'from UserRole where user.id=:userId and role.id=:roleId', [userId: userId, roleId: roleId] } static UserRole create(User user, Role role, boolean flush = false) { new UserRole(user: user, role: role).save(flush: flush, insert: true) } static boolean remove(User user, Role role, boolean flush = false) { UserRole instance = UserRole.findByUserAndRole(user, role) if (!instance) { return false } instance.delete(flush: flush) true } static void removeAll(User user) { executeUpdate 'DELETE FROM UserRole WHERE user=:user', [user: user] } static void removeAll(Role role) { executeUpdate 'DELETE FROM UserRole WHERE role=:role', [role: role] } static mapping = { id composite: ['role', 'user'] version false } } On Thu, Mar 1, 2012 at 6:37 PM, michael astreiko [via Grails] <[hidden email]> wrote:
|
|
Ravi,
Have you solved this issue? I also need to filter by role, and I'm encountering the same issue. Regards, Jonathan
On Fri, Mar 2, 2012 at 12:04 PM, Ravi Pratap <[hidden email]> wrote: it is the default generated by spring-security-core |
| Powered by Nabble | Edit this page |
