Query.setProperties(Map) silently ignores null values provided in the Map

Description

In a Query.setProperties(Map) method was introduced to set query named parameters using a Map. Unfortunately this method silently ignores null values contained in the Map.

See org.hibernate.internal.AbstractQueryImpl.setProperties(Map), here it is checked whether the value is not null. Only if it is not null it is added as parameter.

However the Javadoc clearly states that there are Map implementations which contain null values, a return value of null for the java.util.Map.get(Object) method does not necessarily indicate that the key is not contained in the Map. To check whether a key is contained in the Map, the containsKey(Object) method should be used.

If it is not possible to fix the Query.setProperties(Map) method, the Javadoc regarding this method should at least include a hint that null values are never bound to the named parameters using this method. It might be difficult to bind the null values, because the original type of these values is not known anymore in this method.

Activity

Andrea BorieroJune 3, 2016 at 11:26 AM

Hi ,

it's not the desire behaviour.

I have opened a new jira https://hibernate.atlassian.net/browse/HHH-10796.

Thanks for reporting the issue.

Miroslav ŠilhavýJune 3, 2016 at 10:49 AM

Is it correct that even though the parameter is not in the Map, it's value is set by the setProperties method to null?

Example
Query query = session.createQuery("SELECT user FROM User user WHERE user.id IN (:ids) AND user.status IN (:statuses)");

query.setParameterList("statuses",statusList);
map.put("ids", idList);
query.setProperties(map);

Before the fix this worked without problems, but now the Map sets the value of "statuses" to NULL. I don't think this is desired behavior as the Map should be checked by contains() method before setting the value.

Thanks

Andrea BorieroFebruary 1, 2016 at 6:26 PM

Matthias OtterbachFebruary 1, 2016 at 1:00 PM

Thanks for the verification and sorry for my missing reply, I just added version 5.0.6 to the Affects version field.

Tom EicherFebruary 1, 2016 at 12:46 PM
Edited

just verified against 5.0.6. this bug still applies. (I am not allowed to edit the "affects" field)

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

Created October 22, 2012 at 10:21 AM
Updated June 3, 2016 at 11:27 AM
Resolved February 4, 2016 at 2:26 PM