Hibernate is ignoring my data from a Map
when it is null.
If I hedge with setParameter("nome",valor)
and the value is null it works, does anyone know how to solve it? Here is the code:
public List selectList(String sp, Map params, Class type) {
List list = new ArrayList();
try {
Query query;
if (type != null) {
query = session.createSQLQuery(strSelect + sp).addEntity(type).setProperties(params);
session.clear();
list = query.list();
return list;
} else {
query = session.createSQLQuery(sp).setProperties(params);
session.clear();
list = query.list();
return list;
}
} catch (Exception e) {
e.printStackTrace();
return list;
}
}
The error:
Severe: org.hibernate.QueryException: Not all named parameters have been set: [oCodDep] [Select * From SP_CADDEP_SELECT_11 (: oCodDep, : oNomDep, null, null, null)] at org.hibernate.internal.AbstractQueryImpl.verifyParameters (AbstractQueryImpl.java:401) at org.hibernate.internal.SQLQueryImpl.verifyParameters (SQLQueryImpl.java:195)
In this case, the value sp
I am passing as a parameter would be this:
"Select * From SP_CADDEP_SELECT_11(:oCodDep, :oNomDep, null, null, null)"
I have the option of not passing oCodDep
nor oNomdep
, but when it goes null
setProperties
is ignoring.
Note: I can not go with setParameter
.