I am using nativeQuery in my repository which fetches data from multiple tables using join and it also checks for inputs sent by the user within the query. My Repository layer looks something like:
@Query(
value = "SELECT e.empname,c.countryName,r.RegionName
FROM Employee e,Country c, Region r
WHERE e.countryId=c.countryId
AND c.regionId=r.regionId
AND e.employeeId IN (:empIds)
AND c.countryId IN (:countryIds)
AND r.regionId IN (:regionIds)",
nativeQuery = true)
Collection<Object> findAllActiveUsersNative(CustomFilterRequest request,Pageable pageable);
Following is my filter Class which are lists of IDs sent from the UI and this list properties of class should be sent to query for further filtering.
class CustomFilterRequest{
List<Long> empIds,
List<Long> countryIds,
List<Long> regionIds,
}
I know there's @Param which can be used for sending individual query parameters but how to send multiple query parameters as in the scenario mentioned above? Is there any way to map properties of this class to query parameters in the nativeQuery of @Query?