HQL issue with hasMany String

In the context of this problem:

I have a Grails class:

class User{
   long id
   static hasMany = [skills: String]
   ...
}

I want users from db on two conditions:

  • set of identifiers
  • skill set (lines)

I wrote this query that works for identifiers, but I cannot get some of the skill to work:

User.findAll( "from User 
where id in (5067120,5067121,...5067139)" )

At the moment, I select users with the right skills manually after this request, but obviously this is not an effective solution. How can i solve this?

Thank!

+3
source share
1 answer

This should work:

def ids = [5067120L, 5067121L, ...5067139L]
def skills = ['skill 1', 'skill 2']

def users = User.executeQuery(
   'select distinct u ' +
   'from User u inner join u.skills skills ' +
   'where u.id in (:ids) and skills in (:skills)',
[ids: ids, skills: skills])

Please note that you do not need to specify an id field if it is regular, Grails does it for you.

+4
source

Source: https://habr.com/ru/post/1790324/


All Articles