1
Hibernate is ignoring my data from a Map
when it is void.
If I’m with setParameter("nome",valor)
and the value is null it works, does anyone know how to solve? Follow 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 mistake:
Grave: 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
that 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 the oCodDep
nor the oNomdep
, but when will null
the setProperties
is ignoring.
Note: I can not pass with setParameter
.
Hello, Felipe! I don’t understand it well. When you pass a null value in Map SQL works and the attribute is ignored?
– Dherik
When I pass a null value in the map, let’s do the parameter oCodDep , sql does not work pq says q is missing parameter "Not all named Parameters have been set" however when I do not use the setProperties and step parameter by parameter with setParameter it works
– Felipe Henrique
Which version of Hibernate is using?
– Dherik
There are at least two issues related to this. That is, you probably found a bug in Hibernate. The problem is fixed from version 5.1 of Hibernate. I suggest to try a version with the fix and check if it solves your problem.
– Dherik