@Query("SELECT adv FROM Advocacyadv where (adv.patient.facilityId IN (:facilityIds) or :facilityIds is null) "
+ " order by adv.createdDate desc ")
public List<Advocacy> search(
@Param("facilityIds") Integer[] facilityIds);
The above code gives the following error
Caused by: java.lang.IllegalArgumentException: Encountered array-valued parameter binding, but was expecting [java.lang.Integer (n/a)]
My search may or may not have search parameters. If there are no search parameters, I want all the data to show up. If there are search parameters, I only need those that match. How can I accomplish this using JPA?
You need to use a list
Query("SELECT adv FROM Advocacyadv where (adv.patient.facilityId IN (:facilityIds) or :facilityIds is null) "
+ " order by adv.createdDate desc ")
public List<Advocacy> search(
@Param("facilityIds") List<Integer> facilityIds);
Update:
The correct query is as follows:Query(
"SELECT adv FROM Advocacy adv " +
"WHERE (:facilityIds IS NULL OR adv.patient.facilityId IN :facilityIds) " +
"ORDER BY adv.createdDate DESC")
public List<Advocacy> search(@Param("facilityIds") List<Integer> facilityIds);