title: How to dynamically search between two dates in hql?
body: <p>I have two Date search field namely from and to. I have to retrieve records from the user table whose startDate lies between the from and to dates entered in the search fields and if the from and to dates are null I have to retrieve all the records from the user table.</p>
  
  <p>I tried the following hql query:</p>
  
  <pre><code>FROM USER 
  WHERE 
  :start_flag =1 
  OR  
  STARTDATE between :from and :to
  </code></pre>
  
  <p>Here start_flag is of type int which is set to 1 if from and to are null.</p>
  
  <pre><code>query.setParameter("from",startDt);
  query.setParameter("to",endDt);
  query.setParameter("start_flag",startFlag);
  l=  query.list();
  </code></pre>
  
  <p>Here datatypes are:</p>
  
  <p>startDt - java.util.Date</p>
  
  <p>endDt- java.util.Date</p>
  
  <p>startFlag- int</p>
  
  <p>When I run the above query with <strong>to and from equal to null</strong> I get the following exception:</p>
  
  <p>SQL Error: 932, SQLState: 42000</p>
  
  <p>ORA-00932: inconsistent datatypes: expected DATE got BINARY</p>
  
  <p>Could you tell me how to write the HQL query to achieve the above functionality ?</p>