I am using JPA, hibernate 3.
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());
This query works like a charm when there were no empty or zero values. But it may be possible to zero or empty for traceEntityVO.getLotNumber (), traceEntityVO.getMfrLocId (), traceEntityVO.getExpDate ().
In this case, the value "null" or "" is checked for a variable instead of a condition - this is the value null . How do I handle when I'm not sure about the value of a parameter, either empty or empty?
I do not want to build the query dynamically based on the values, if empty or null.
Is it possible?
Thanks in advance.
Prathap
source share