title: Matching hasMany children with Grails dynamic finders
body: <p>In Grails, I'm attempting to find an instance of a domain class that has exact entries in a one-to-many relationship. Consider this example:</p>
  
  <pre><code>class Author {
      String name
      List&lt;Book&gt; books
  
      static hasMany = [books:Book]
  }
  
  class Book {
      String title
  
      static belongsTo = Author
  }
  </code></pre>
  
  <p>My database then appears as such:</p>
  
  <pre><code>author                     book
  -------------------------    ------------------------
  | id | name             |    | id | title           |
  |----|------------------|    ------------------------
  | 1  | John Steinbeck   |    | 1  | Grapes of Wrath |
  | 2  | Michael Crichton |    | 2  | East of Eden    |
  -------------------------    | 3  | Timeline        |
                               | 4  | Jurassic Park   |
                               ------------------------
  
  author_book
  ----------------------------------------
  | author_books_id | book_id | book_idx |
  ----------------------------------------
  | 1               | 1       | 0        | // John Steinbeck - Grapes of Wrath
  | 1               | 2       | 1        | // John Steinbeck - East of Eden
  | 2               | 3       | 0        | // Michael Crichton - Timeline
  | 2               | 4       | 1        | // Michael Crichton - Jurassic Park
  ----------------------------------------
  </code></pre>
  
  <p>What I'd like to be able to do is use a dynamic finder on author. I'm searching for an exact match on the hasMany relation, to match this behavior:</p>
  
  <pre><code>Author.findByBooks([1]) =&gt; null
  Author.findByBooks([1, 2]) =&gt; author(id:1)
  Author.findByBooks([1, 3]) =&gt; null
  Author.findByBooks([3, 4]) =&gt; author(id:2)
  </code></pre>
  
  <p>Attempting this results in an ugly Hibernate error:</p>
  
  <pre><code>hibernate.util.JDBCExceptionReporter No value specified for parameter 1.
  </code></pre>
  
  <p>Has anyone had dynamic finders work with hasMany relationships of domain classes? What is the most 'Grails-y' solution to get the desired behavior?</p>