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 8294767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:20:22+00:00 2026-06-08T14:20:22+00:00

I am currently working on a grails project right now where I needed to

  • 0

I am currently working on a grails project right now where I needed to combine the result of my query in a list. The problem is, there are instances that the result of my query returns equal values, which causes an error message: A different object with the same identifier value was already associated with the session

Here’s my code:

List permissions = []
            cmd?.role.each{ role ->
                permissions.add(RolePermission.executeQuery("select distinct rp.permission from RolePermission rp where rp.role = ?",[Role.get(role.toLong())]))
            }

The object role here may contain two different role names that in some instances the permissions present in these role names are the same.

How will I modify my query in such a way that I can only get the unique values from the result ? I’ve tried using distinct, but it didn’t work.

Please help!

Thanks!

  • 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-06-08T14:20:23+00:00Added an answer on June 8, 2026 at 2:20 pm

    I’m not sure if this is what you’re trying to do, but from your description I think this is it. What the below line does is iterate over your passed in roles (I assume these are role id’s from the syntax) and for each role id it finds a RolePermission for the Role. Each permission found is added as a list to permissions. So, at the end you should have a list of RolePermissions.

    Now, what I’m not understanding is the distinctness your looking for. Are you saying that a Role can return more than one RolePermission and your trying to make sure that the returned RolePermissions are unique in the final list? If so you could return the list as a set (i.e. return permissions as Set). Please let me know where my understanding falls short.

    def permissions = cmd?.role.collect{RolePermission.findByRole(Role.get(it.toLong()))}
    return permissions as Set
    

    Alternatively, you could use a criteria:

    def c = RolePermission.createCriteria()
    def results = c.listdistinct () {
      roles {
        'in'("id", cmd?.role as List) 
      }
    }
    

    I didn’t run this through the compiler, but it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am now currently working on a grails project . I have a problem
I am currently working on grails project. I have created eight different plugins. Each
I am currently working on a grails project where I need to execute a
I'm currently working on a project using netbeans 6.9 and grails 1.3. I'm trying
I'm a newbie on grails. I am now currently working on my scaffolding templates
Currently working on a flex AIR project based on PureMVC framework. There was a
Im currently working on a project that requires the following. I need to be
Im currently working on a c# project that uses another .net library. This library
Currently working on a project that is being developed in VS2010. I'm running Windows
I am currently working on a filter in Grails that will allow me to

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.