title: How to make this short in Grails or Hibernate
body: <p>I've got query that looks something like this:</p>
  
  <pre><code>SomeDomain.executeQuery("""
      from
          SomeDomain x
      where
          x.linkToSomeA = coalesce(:a, x.linkToSomeA) and
          x.linkToSomeB = coalesce(:b, x.linkToSomeB) and
          ...
      """,
      [a: someA, b: someB, ...]
  )
  </code></pre>
  
  <p>The intended behaviour is as follows: once <code>null</code> is supplied for a criterion parameter, this criterion should be ignored. If anything other than <code>null</code> is supplied, the criterion is used.</p>
  
  <p>Everything would work fine, except that Hibernate doesn't allow supplying <code>null</code> where domain class instances are expected. So in the end this is not a valid query (in fact <code>NullPointerException</code> will be thrown if any <code>null</code>s are supplied).</p>
  
  <p>I haven't found any way to rewrite this without using a ton of <code>if-else</code>. Does anybody have any idea how to make this about <strong>equally brief and valid</strong> at the same time?</p>
  
  <p>NOTE: The real query is more complicated than that so please, do not suggest rewriting this using anything else than <code>executeQuery</code>.</p>