With criteria builder, I’m calling a function which has a collection as parameter. This fails with a NullPointerException when hibernate validates the types.
My code (simplified), where I define a generic “contains in array” check.
{code:java} protected <T> Predicate contains(Expression<Collection<T>> array, T value) { return criteriaBuilder.equal(criteriaBuilder.literal(value), criteriaBuilder.function("ANY", Object.class, array)); }{code}
This My goal is to query an array-column, something like: struture with an array-column: {{ALTER TABLE person ADD COLUMN tel_numbers VARCHAR ARRAY;}} with Postgres specific: {{SELECT * FROM person p WHERE '+123456' = ANY(p.tel_numbers)}} or eventually SQL-Standard: {{SELECT * FROM person p WHERE '+123456' = ANY(SELECT * FROM UNNEST(p.tel_numbers));}}
The function definition fails at {{ArgumentTypesValidator.validate:92}} with a {{NullPointerException}}:
{{final JdbcType jdbcType = getJdbcType( queryEngine, argument, indicators, javaType );}} // → null {{jdbcType.getDefaultSqlTypeCode()}} → NullPointerException The {{ArgumentTypesValidator.getJdbcType:139}} calls {{javaType.getRecommendedJdbcType}} and {{CollectionJavaType.getRecommendedJdbcType}} always returns {{null}}. I think that {{ArgumentTypesValidator.validate}} should handle a {{null}} jdbcType properly, in that case not doing the validation.
Or what is your opinion? Is there a workaround? |
|