title: Ibatis / Ibator - How to properly write a "complex" WHERE clause using Example classes and Criteria?
body: <p>I want to perform a <code>SELECT</code> with several conditions, using Ibator's generated Example classes.</p>
  
  <p>As described <a href="http://ibatis.apache.org/docs/tools/abator/generatedobjects/exampleClassUsage.html#java2" rel="nofollow">here in the usage notes</a>, it's fairly easy to use <code>criteria.andFieldIsSomething()</code> and <code>example.or(example)</code> to compose a <code>WHERE</code> clause with multiple <code>OR</code> and <code>AND</code> operators.</p>
  
  <p>I could just write this:</p>
  
  <pre><code>example.createCriteria().andIntegerIsEqualTo(int).andDateIsEqualTo(someday);
  example.or(example.createCriteria().andIntegerIsNull().andDateIsEqualTo(someday));
  example.or(example.createCriteria().andIntegerIsEqualTo(int).andDateIsNull());
  example.or(example.createCriteria().andIntegerIsNull().andDateIsNull());
  </code></pre>
  
  <p>But first, it's kind of tedious and redundant, and it would output the following code:</p>
  
  <pre><code>SELECT * FROM zeTable
  WHERE (integer = int AND date = someday)
  OR (integer IS NULL AND date = someday)
  OR (integer = int AND date IS NULL)
  OR (integer IS NULL AND date IS NULL);
  </code></pre>
  
  <p>A more elegant (and probably efficient) way of writing that would be:</p>
  
  <pre><code>SELECT * FROM zeTable
  WHERE (integer IS NULL OR integer = int)
  AND (date IS NULL OR date = someday);
  </code></pre>
  
  <p>The test for <code>NULL</code> prevents me from using the <code>.andFieldSomethingIn(List values)</code> method efficiently, and while I kept this example simple, the code I have to write implies crossing 5 or 6 fields like that, which could amount to 36 different Criteria.</p>
  
  <p>This seems ridiculous to me, so I assume there must be a better way. Can someone suggest something ?</p>