Spring data native query filtering by List<String>

248 Views Asked by At

Given: Interface projection model with

 String getType();

Postgres 13; Hibernate+JPA+Spring data; Query filter:

   " where ... "
 + " and (COALESCE(:types) is null or model.type in (:types)) "

Pageable method in repository contains param

 @Param("types") @Nullable List<String> types

generated SQL when null types is being passed:

and (COALESCE(?) is null or folderModel.contentType in (?)) 

error after it thrown:

org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying = bytea
  Tips: No operator matches the given name and argument types. You might need to add explicit type casts.

There is no problem when I pass any nullable params in 'where' clause likewise when types isn't null and contains valid types. I tried to cast(model.type to varchar) with no any success. Any ideas?

0

There are 0 best solutions below