List params are not expanded in native queries
See original GitHub issueThe query below is not expanded into for the list and an exception is thrown
@Query(value = "select t.* from hcp_tenant t " +
"join hcp_tenant_consumer tc on tc.tenant_id = t.id and tc.topic_id in :topicIds",
nativeQuery = true)
Set<HcpTenantDTO> findByConsumersTopicsIdInList(List<Long> topicIds);
I have tried (:topicIds)
as well but same result as the expansion isn’t happening
SELECT hcp_topic_.`id`,hcp_topic_.`name`,hcp_topic_.`partitions`,hcp_topic_.`config`,hcp_topic_.`email`,hcp_topic_.`ms_id`,hcp_topic_.`compatibility`,hcp_topic_.`aha_id` FROM `hcp_topic` hcp_topic_ INNER JOIN `hcp_org` hcp_topic_hcp_org_ ON hcp_topic_.`hcp_org_id`=hcp_topic_hcp_org_.`id` INNER JOIN `hcp_env` hcp_topic_hcp_org_env_ ON hcp_topic_hcp_org_.`env_id`=hcp_topic_hcp_org_env_.`id` WHERE (hcp_topic_hcp_org_env_.`id` = ?)
10:09:13.254 [pool-2-thread-7] DEBUG io.micronaut.data.query - Executing Query: select t.* from hcp_tenant t join hcp_tenant_consumer tc on tc.tenant_id = t.id and tc.topic_id in ?
10:09:13.290 [pool-2-thread-7] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: Unable to set PreparedStatement value: Parameter index out of range (2 > number of parameters, which is 1).
io.micronaut.data.exceptions.DataAccessException: Unable to set PreparedStatement value: Parameter index out of range (2 > number of parameters, which is 1).
at io.micronaut.data.jdbc.mapper.JdbcQueryStatement.newDataAccessException(JdbcQueryStatement.java:273)
at io.micronaut.data.jdbc.mapper.JdbcQueryStatement.setLong(JdbcQueryStatement.java:139)
at io.micronaut.data.jdbc.mapper.JdbcQueryStatement.setLong(JdbcQueryStatement.java:33)
at io.micronaut.data.runtime.mapper.QueryStatement.setDynamic(QueryStatement.java:134)
at io.micronaut.data.jdbc.mapper.JdbcQueryStatement.setDynamic(JdbcQueryStatement.java:92)
at io.micronaut.data.jdbc.mapper.JdbcQueryStatement.setDynamic(JdbcQueryStatement.java:33)
...
Caused by: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.ClientPreparedStatement.checkBounds(ClientPreparedStatement.java:1402)
at com.mysql.cj.jdbc.ClientPreparedStatement.getCoreParameterIndex(ClientPreparedStatement.java:1415)
at com.mysql.cj.jdbc.ClientPreparedStatement.setLong(ClientPreparedStatement.java:1610)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setLong(HikariProxyPreparedStatement.java)
at io.micronaut.data.jdbc.mapper.JdbcQueryStatement.setLong(JdbcQueryStatement.java:137)
... 127 common frames omitted
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (11 by maintainers)
Top Results From Across the Web
Passing List<Integer> in spring data jpa native query
A JPQL query allows the JPA provider to create the SQL it needs dynamically based on the list passed in, so it can...
Read more >DataReadQuery List parameter for IN clause — oracle-tech
Lists will not be expanded on when using native SQL as it would require parsing and manipulating the SQL string passed in.
Read more >Define and Call Data Queries - ForgeRock Backstage
Define and Call Data Queries. An advanced query model enables you to define queries and to call them over the REST or Resource...
Read more >Running parameterized queries | BigQuery - Google Cloud
Note that a query can use positional or named parameters but not both. ... Construct the value as a comma-separated list of elements...
Read more >Bash Reference Manual - GNU.org
is not removed. The special parameters ' * ' and ' @ ' have special meaning when in double quotes (see Shell Parameter...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am facing the same problem:
io.micronaut.data.exceptions.DataAccessException: Unable to set PreparedStatement value: Invalid value "2" for parameter "parameterIndex" [90008-200]
Any updates on this?
Btw the value for ids was [2, 4] in this case.
Would you give a try to fix regex @zhuravskiy? 😃