title: How to handle if query parameter is null or empty in hibernate?
body: <p>I'm using JPA, hibernate 3. </p>
  
  <pre><code>String sqlQuery = " FROM TraceEntityVO  where lotNumber =:lotNumber and mfrLocId=:mfrLocId and mfrDate=:mfrDate and qtyInitial=:qtyInitial and expDate=:expDate";
  Query query = entityManager.createQuery(sqlQuery)
                  .setParameter("lotNumber", traceEntityVO.getLotNumber())
                  .setParameter("mfrLocId", traceEntityVO.getMfrLocId())
                  .setParameter("mfrDate", traceEntityVO.getMfrDate())
                  .setParameter("qtyInitial", traceEntityVO.getQtyInitial())
                  .setParameter("expDate", traceEntityVO.getExpDate());
  </code></pre>
  
  <p>This query works like a charm when the there were no empty or null values. But there could be possible of null or empty value for <strong><em>traceEntityVO.getLotNumber(),traceEntityVO.getMfrLocId(),traceEntityVO.getExpDate().</em></strong> </p>
  
  <p>In this case the value 'null' or '' is checked against the variable instead of <strong>is null</strong> condition. How do I handle when I'm not sure about the parameter value, either null or empty?</p>
  
  <p><em><strong>I don't want to construct the query dynamically based on the values if empty or null.</em></strong></p>
  
  <p>Is this possible?</p>
  
  <p>Thanks in advance..</p>