title: conditional set parameter in hibernate
body: <p>I have this table:</p>
  
  <h2>Contract</h2>
  
  <h2>| id | personId | initDate | endDate |</h2>
  
  <p>I would like to include in hibernate query the personId just when personId > 0 and/or a between with the dates when they are different from null.</p>
  
  <p>I have: </p>
  
  <pre><code>Query query = session.createQuery("from Contract")
  </code></pre>
  
  <p>How can I set the parameters correctly after check the conditions?</p>
  
  <pre><code>public List&lt;Contract&gt; getByPersonIdAndDates(int personId, Date initDate, Date endDate) {
          if(personId &gt; 0)
  ...
          if(initDate != null and endDate != null)
  ...
  </code></pre>