title: Hibernate: Looking for a way to simplify how I search for objects using an object
body: <p>I'm using Hibernate Core 3.3.4.GA.  I'm looking for a way to simplify my code (if possible).  Right now, I want to search for objects of type "MyObj" using an instance of MyObj, which will be partially populated.  So I have …  </p>
  
  <pre><code>// inputObj is a partially populated object of type MyObj
  Criteria crit = session.createCriteria(MyObj.class);
  if (inputObj.getField1() != null) { 
      crit.add( Restrictions.eq( "field1", inputObj.getField1() );
  }
  if (inputObj.getField2() != null) { 
      crit.add( Restrictions.eq( "field2", inputObj.getField2() );
  }
  …
  List objects = crit.list();
  </code></pre>
  
  <p>Problem is, there is more than 20 fields, so the code is onerous.  Is there a way to simplify the above?</p>
  
  <p>Thanks, - Dave</p>