I have a sql statement as below and want to convert it to JPA
SELECT * FROM employee
where user_id in ('id1', 'id2', 'id3')
AND (
first_name like '%name1%' OR last_name like '%name1%'
OR
first_name like '%name2%' OR last_name like '%name2%'
)
ORDER BY user_id ASC;
Input parameter
userIdList - a list of string to exact match user_id of size [1,100]
nameList - a list of string to like-wise match first_name or last_name of size [1,100] in character [A-Za-z0-9-_ ]
example for name list: ['Joe', 'Peter', 'White', 'X Y']
I have no idea about how to handle the List of like part and the closest I have is without the list of like
@Modifying
@Query(value = "select * from employee where user_id IN :ids ORDER BY user_id",
nativeQuery = true)
List<UserGroupTable> findAllByUserIdList(@Param("ids") List<String> userIdList);
In clause reference: %Like% Query in spring JpaRepository