title: Grails: find by one-to-many association with String
body: <p>I have a following domain class:</p>
  
  <pre><code>class User {
     static hasMany = [roles:String]
  }
  </code></pre>
  
  <p>I would like to find every user which has role <code>ROLE_ADMIN</code>. Is there any possibility to do that with dynamic finders? <code>user.findAllByRoles('ROLE_ADMIN')</code> seems to give me an error.</p>
  
  <p>UPDATE: it is quite easy to query association where Class <code>A</code> has a list of class <code>B</code> instances and both <code>A</code> and <code>B</code> are domain classes. But here class <code>A</code> is a domain class and class <code>B</code> is a simple Java string.</p>
  
  <p>The code for querying association containing list of another domain objects would look like this:</p>
  
  <pre><code>`User.findAll { roles { role_name=='ROLE_ADMIN' } }`
  </code></pre>
  
  <p>What i am looking for is a way to specify the value of a String, for example:</p>
  
  <pre><code>`User.findAll { roles {THIS_VALUE=='ROLE_ADMIN' }}`
  </code></pre>
  
  <p>UPDATE 2: as far as i have found it is not possible to use criteria with collections of primitive types. It is possible to use HQL though:</p>
  
  <pre><code>User.findAll("from User a where :roles in elements(roles)",[roles:'ROLE_ADMIN'])
  </code></pre>
  
  <p>However it is not as usefull as a <code>findAll</code> or <code>where</code> query. I cannot chain <code>findAll</code> methods so defining other methods that for example: get <code>ROLE_ADMIN</code> users with username like 'xxx' requires rewriting whole <code>HQL</code> query. Maybe it is possible to express above <code>HQL</code> condition in form of a <code>where</code> expression?</p>