13

I have some queries like this:

List listOfIntegers = Arrays.asList(new Integer[] {1, 2, 3});
List objects = 
    namedParameterJdbcTemplate.query("select * from bla where id in ( :ids )",
            Collections.singletonMap("ids", listOfIntegers),
            myRowMapper);

This will send this SQL query to the database:

select * from bla where id in ( 1, 2, 3 )

Now I want to send this type of query to the database:

select * from bla where (id,name) in ( (1,'foo'), (2,'bar'), (3,'foobar'))

Do I need to pass a List<List<Object>> to accomplish this? Will it work with Spring JDBCTemplate?

  • Tested with List> and it did not work. Debugging the Spring code that handles the list of integers I saw that it generates a series of '?' for each element in the list. – Constantino Cronemberger Apr 28 '14 at 13:31

1 Answers1

18

I have debugged Spring code and found that it expects tuples to be provided as Object[], so for it to work with a List it should be a List<Object[]>.

  • Hi, could you take a look at this question. https://stackoverflow.com/questions/55877193/spring-jpa-repository-jpql-query-using-a-collection-of-objects – andresscode Apr 27 '19 at 05:53