HQL no longer deals with empty collections as bind values for nullness predicates in junction with other predicates
Description
Attachments
duplicates
Activity
Alex Nistico September 18, 2023 at 2:27 AM
While it is true that a collection_valued_input_parameter
is the only allowed parameter in the IN clause, I think a collection parameter can be used in other contexts. Specifically to this case, the null comparison expression grammar is:
Now, the JPQL BNF does not have an explicit production for input_parameter
, but I think it would be safe to assume that it means ‘any parameter type defined in the grammar’, which would include collection_valued_input_parameter
. Obviously that is an interpretation and the grammar is ambiguous without that production, but in this specific case I believe that it makes sense to be able to determine whether a parameter, not a path_expression, is null or not in terms of whether the value that is passed through the parameter is null or not.
Marco Belladelli September 6, 2023 at 3:00 PM
We have introduced a check for this unsupported behavior, you should now obtain a clear error message. See for additional details.

Christian Beikov August 30, 2023 at 4:14 PM
You want to do dynamic filtering, so why are you using a static HQL query? The HQL grammar also accepts other constructs which might fail at later stages, so just because it parses doesn’t mean it’s “supported”.
Multi-valued parameters are only allowed for the IN
predicate. If you check the documentation, you will see that multi-valued parameters are only ever used in examples for the IN
predicate:
In addition, the JPA specification explicitly states through the grammar that there is only one place where such a collection valued parameter is allowed, which is the IN
predicate. Here the excerpt from the grammar:
It seems someone in the past found out that Hibernate 4 and 5 didn’t validate the uses of parameters well enough and started promoting this bad approach. Using a multi-valued parameter just happened to work by accident in other contexts, but was also producing garbage SQL in some cases. Until Hibernate 6 we simply didn’t have enough information in the AST to properly validate this and now that we do, many people complain that this doesn’t work anymore.
But you should be happy this doesn’t work anymore, because now you have the opportunity to fix your code and quite possibly get better performance from your query due to that.
Alex Nistico August 22, 2023 at 2:27 AM
Criteria API is not always possible to use, for example when using @Query in Spring Data repositories. The HQL grammar accepts the idiom and I could not find any reference in current documentation saying that that is not allowed.
Marco Belladelli August 4, 2023 at 12:47 PM
This pattern is no longer allowed, you should avoid it and instead use Criteria API for conditional predicates. Please refer to 's comment in for more information.
Named parameters that accepts collections and are used in nullness predicates combined with other predicates, for example in clauses , fail to bind the value.
For example
Will throw the following exception:
The expected result would be to retrieve an empty result when we pass an empty collection or array to the parameter.
Please use the “fixed” zip for a reproduction, Jira would not allow me to delete the incorrect one.