question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple Columns In Clause Parameters [DATAJPA-1278]

See original GitHub issue

ooxaam opened DATAJPA-1278 and commented

I’m new to spring jpa and what I’m trying to do is that:

I have a list of accounts and currency and I want to search from table based on both of these params by passing them “IN” clause.

What I’m doing right now is :

@Query(nativeQuery = true, value = "select a.* from ACC a where (a.iban, a.currency) in (:iban , :curr)")
    List<ACC> getAccount(@Param("iban") List<String> ibans, @Param("curr") List<String> currencies);

Expecting a query like this:

select * from table where (iban, curr) in (('accnum1', 'currency1'),('accnum2', 'currency2'), ('accnum3', 'currency3'));

Actually query is getting generated like this:

select * from table where (iban, curr) in (('accnum1', 'accnum2', 'accnum3'),('currency1', 'currency2', 'currency3'));

No further details from DATAJPA-1278

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
spring-projects-issuescommented, Dec 30, 2020

Jens Schauder commented

Could you try

@Query(nativeQuery = true, value = "select a.* from ACC a where (a.iban, a.currency) in (:param)")
List<ACC> getAccount(@Param("param") List<String[]> params);

where params gets passed the tuples as 2-element-arrays.

I don’t think how this is supposed to behave is specified in any relevant standard.

The “Bugfix” would need to come for JPA by actually specifying how to achieve something like this with JPQL. In the meantime, I’d recommend falling back to Springs JdbcTemplate which supports this kind of query. See https://stackoverflow.com/questions/23305553/how-to-bind-a-list-of-tuples-using-spring-jdbctemplate

0reactions
spring-projects-issuescommented, Dec 30, 2020

Jens Schauder commented

Batch closing resolved issue without a fix version and a resolution indicating that there is nothing to release (Won’t fix, Invalid …)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parameterized IN clause using multiple columns
I have a query along these lines, where I am trying to filter the result set by comparing tuples (like SQL multiple columns...
Read more >
Selecting Multiple Columns Based On Condition in SQL
When we have to select multiple columns along with some condition, we put a WHERE clause and write our condition inside that clause....
Read more >
SELECT - Snowflake Documentation
As a clause, SELECT defines the set of columns returned by a query. ... 'Dana', 2); INSERT INTO department_table (department_ID, department_name) VALUES (1, ......
Read more >
selecting where two columns are in a set - DBA Stack Exchange
works in PostgreSQL, DB2, SQL Server SELECT t.whatever FROM t JOIN ( VALUES (val1a, val2a), (val1b, val2b), ...) AS x (col1, col2) ON...
Read more >
Sorting on multiple columns - IBM
The default is still ascending, and the column that is listed first in the ORDER BY clause takes precedence. The following query and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found