Closed
Description
The following query doesn't work any more with spring-data-jdbc versions 2.4.1 & 2.4.2. It works in version 2.4.0.
@Query(
"select distinct s.id_external from shell s where s.id in (" +
"select si.fk_shell_id from shell_identifier si " +
"join (values :keyValueCombinations ) as t (input_key,input_value) " +
"ON si.namespace = input_key " +
"AND si.identifier = input_value " +
"group by si.fk_shell_id " +
")"
)
List<String> findExternalShellIdsByIdentifiers(@Param("keyValueCombinations") List<String[]> keyValueCombinations);
The invocation of the method is like this:
List<String[]> keyValueCombinations = List.of(new String[]{"key1", "value1"}, new String[]{"key2", "value2"});
findExternalShellIdsByIdentifiers(keyValueCombinations)
I tested it with PostgreSQL and H2.
PostgreSQL
Version: postgres:13.6-alpine
Driver-Version: 42.5.0
Error:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [select s.id_external from shell s where s.id in (select si.fk_shell_id from shell_identifier si join (values ?, ?, ? ) as t (input_key,input_value) ON si.namespace = input_key AND si.identifier = input_value group by si.fk_shell_id having )]; nested exception is org.postgresql.util.PSQLException: Cannot cast an instance of java.util.ArrayList to type Types.ARRAY
H2
Version: 2.1.214
Error:
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Column count does not match; SQL statement:
select s.id_external from shell s where s.id in (select si.fk_shell_id from shell_identifier si join (values ?, ?, ? ) as t (input_key,input_value) ON si.namespace = input_key AND si.identifier = input_value group by si.fk_shell_id ) [21002-214]
The issue seams to be here:
2.4.0...2.4.2#diff-b8453546f8ae7cc224005f536bb3be8a0c341186f2cf38b2b34d958cc769ac4cR171
The if
condition should evaluate to false
for Iterable
s containing array objects.