folks,
I have a problem finding a way to send parameters for IN clause in a native query through Spring data repository. I tried sending list of strings, concatenated and formatted strings... nothing helped
folks,
I have a problem finding a way to send parameters for IN clause in a native query through Spring data repository. I tried sending list of strings, concatenated and formatted strings... nothing helped
Here is the solution:
@Repository
public interface Repo extends PagingAndSortingRepository<Log, Long>
{
@Query(value = QUERY, nativeQuery = true)
List<OrderExecutionLog> findTop1OrderByInitiatedAsc(String[] types);
String QUERY = "SELECT log.* " +
"FROM log" +
"WHERE `type` IN (?3) ";
}
I tried several variations with a list or concatenated strings and so on ... but a simple array gave me the desired result. I think that the Spring community need to take a look at this simple issue i encountered.
Good luck. Hope this helps someone like me :)
If you have list of strings which are to be passed as parameter for an IN clause, refer below
@Query(value="SELECT * FROM SOME_TABLE WHERE COLUMN_SOME_NAME IN :someList", nativeQuery = true)
List<T> getList(List<String> someList);