Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7176159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:27:11+00:00 2026-05-28T16:27:11+00:00

Domain outlay: class User { String username static hasMany = [userRoles: UserRole] } class

  • 0

Domain outlay:

class User {
    String username
    static hasMany = [userRoles: UserRole]
}
class Role {
    String authority
}
class UserRole {
    User user
    Role role
    static belongsTo = [User, Role]
}

That is a condensed version of what you’ll normally find when you install the grails spring-security-core plugin.

Now, a user can have more than one role. Thus, an admin can be a normal user. User:UserRole = 1:M

In SQL it would be easy to get a set of users where there isn’t a user role attached to it.
How does one do it with the Grails criteria builder?

As a stop gap fix (until I get a nice answer that is not basically plugging SQL into Grails), I basically get all the admin users as a set, then I get the list of users as another, and one for one remove all the admin user out. Ugly, but it works (slowly):

def existing = UserRole.createCriteria().listDistinct {
    eq("role",adminRole)
}.collect{it.user} as Set

def f = User.createCriteria().listDistinct {
    userRoles {
        ne("role",adminRole)
    }
}.collect{it} as Set

existing.each { ex ->
        f.each { non ->
            if (non.id == ex.id) {
                f.remove(non)
            }
        }
}

In the code above, if you do f.removeAll(existing) it doesn’t work.

I think this would be a nice question to answer as you can apply the same to other scenarios as well.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:27:11+00:00Added an answer on May 28, 2026 at 4:27 pm

    I’m not sure how to do it with a criteria query, but this HQL works:

    def role = ...
    def usersWithoutRole = UserRole.executeQuery(
       'from User u where u not in ' +
           '(select ur.user from UserRole ur where ur.role=:r)',
       [r: role])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My domain class looks like this: package com.initech.tps class Foo { String stuff static
I have two domain classes: class A { String Name ... } class B
Domain: class Category string Name class Product IDictionary<string, Product> Parents Tables: Categories (ID, Name)
Should Domain Entities be exposed as Interfaces or as Plain Objects ? The User
Given domain model... public class Entity { public int Id { get; set; }
Our domain model is very tightly coupled and some classes that are mapped with
A domain name that we have is using google mail as its backend, but
With Domain Driven Design in mind, how would you implement user Authorization in a
My domain looks something like this: ProductLine hasMany Topic(s) hasMany Subtopic(s). On Subtopic create.gsp
I have an abstract domain object that is consumed by both a web and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.