I need a method that checks whether all ids from the set are presented in the DB, so I wrote this query, but I have a problem with casting a set to an array. I use Postgres.
My method:
@Query(value =
"SELECT COUNT(1) = 0 " +
"FROM unnest(cast((:ids) AS UUID[])) AS checked_id " +
"WHERE checked_id NOT IN (" +
" SELECT DISTINCT(id) " +
" FROM my_table" +
" WHERE id IN (:ids)" +
")",
nativeQuery = true)
boolean allIdsPresented(Set<UUID> ids);
ERROR: cannot cast type record to uuid[]
Hibernate converts it as: SELECT COUNT(1) = 0 FROM unnest(cast((?, ?, ?) AS UUID[])) ....