0
votes

I'm trying to get all Users that follow a certain criteria and have ROLE_USER.

Criteria:

ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}

Question: Is it possible to add to this criteria a condition that will select only the users with ROLE_USER?

I'm using:

Update:

Minimal User Table: enter image description here


Role Table:

enter image description here


UserRole Table:

enter image description here

1
why you finding it difficult? It having all the structure of criteria in your hand.., you just have to add one more line eq("role","ROLE_USER")Suganthan Madhavan Pillai
@Suganthan I don't think you understood the question. :) With your suggestion I'm getting could not resolve property: role of: foo.User.Daddy Pumpkin
Can you able to post your domain model, I think only mapping is enoughSuganthan Madhavan Pillai
And one more point don''t ever share the original data in public system..Suganthan Madhavan Pillai

1 Answers

-1
votes
  ArrayList<User> users = User.createCriteria().list() {
  inList("gender", whichGenderList)
  ne("uid", uid)
  role {
     eq("authority","ROLE_USER")
  }
  profile {
    inList("age", whichAge)
  }
  firstResult(usersPerPage * currentPage)
  maxResults(usersPerPage)
}