Combining two Spring Data query method List parameters
up vote
0
down vote
favorite
I am trying to create an SQL query using Spring Data JPA. Each row of data has two string column identifiers; combined, these two identifiers are unique to a row. I would like to be able to retrieve a list of rows providing two lists of identifiers (one for each column). For example, I have tried something like this,
List<EntityType> findByIdOneInAndIdTwoIn(List<String> idOnes, List<String> idTwos)
That produced the SQL as,
SELECT * FROM table_name t WHERE t.ID_ONE IN (?,?,?,?...) AND t.ID_TWO IN (?,?,?,?...)
Where the questions marks (?) and ellipses (...) are placeholders for actual identifiers.
I would like to produce SQL that looks something like,
SELECT * FROM table_name t WHERE (t.ID_ONE, t.ID_TWO) IN ((?,?),(?,?),...)
I have not been able to figure out how to write the query method to combine the two lists element by element to form tuple query parameters (ID_ONE, ID_TWO). I am fairly new to Spring Data. Is something like this possible?
java sql spring spring-data-jpa
add a comment |
up vote
0
down vote
favorite
I am trying to create an SQL query using Spring Data JPA. Each row of data has two string column identifiers; combined, these two identifiers are unique to a row. I would like to be able to retrieve a list of rows providing two lists of identifiers (one for each column). For example, I have tried something like this,
List<EntityType> findByIdOneInAndIdTwoIn(List<String> idOnes, List<String> idTwos)
That produced the SQL as,
SELECT * FROM table_name t WHERE t.ID_ONE IN (?,?,?,?...) AND t.ID_TWO IN (?,?,?,?...)
Where the questions marks (?) and ellipses (...) are placeholders for actual identifiers.
I would like to produce SQL that looks something like,
SELECT * FROM table_name t WHERE (t.ID_ONE, t.ID_TWO) IN ((?,?),(?,?),...)
I have not been able to figure out how to write the query method to combine the two lists element by element to form tuple query parameters (ID_ONE, ID_TWO). I am fairly new to Spring Data. Is something like this possible?
java sql spring spring-data-jpa
Have you tried NamedNativeQuery?
– AtulK
Nov 9 at 21:55
I also think that this is not possible with Spring Data JPA and even with JPA. You will have to write the query in SQL.
– Simon Martinelli
Nov 10 at 1:48
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to create an SQL query using Spring Data JPA. Each row of data has two string column identifiers; combined, these two identifiers are unique to a row. I would like to be able to retrieve a list of rows providing two lists of identifiers (one for each column). For example, I have tried something like this,
List<EntityType> findByIdOneInAndIdTwoIn(List<String> idOnes, List<String> idTwos)
That produced the SQL as,
SELECT * FROM table_name t WHERE t.ID_ONE IN (?,?,?,?...) AND t.ID_TWO IN (?,?,?,?...)
Where the questions marks (?) and ellipses (...) are placeholders for actual identifiers.
I would like to produce SQL that looks something like,
SELECT * FROM table_name t WHERE (t.ID_ONE, t.ID_TWO) IN ((?,?),(?,?),...)
I have not been able to figure out how to write the query method to combine the two lists element by element to form tuple query parameters (ID_ONE, ID_TWO). I am fairly new to Spring Data. Is something like this possible?
java sql spring spring-data-jpa
I am trying to create an SQL query using Spring Data JPA. Each row of data has two string column identifiers; combined, these two identifiers are unique to a row. I would like to be able to retrieve a list of rows providing two lists of identifiers (one for each column). For example, I have tried something like this,
List<EntityType> findByIdOneInAndIdTwoIn(List<String> idOnes, List<String> idTwos)
That produced the SQL as,
SELECT * FROM table_name t WHERE t.ID_ONE IN (?,?,?,?...) AND t.ID_TWO IN (?,?,?,?...)
Where the questions marks (?) and ellipses (...) are placeholders for actual identifiers.
I would like to produce SQL that looks something like,
SELECT * FROM table_name t WHERE (t.ID_ONE, t.ID_TWO) IN ((?,?),(?,?),...)
I have not been able to figure out how to write the query method to combine the two lists element by element to form tuple query parameters (ID_ONE, ID_TWO). I am fairly new to Spring Data. Is something like this possible?
java sql spring spring-data-jpa
java sql spring spring-data-jpa
edited Nov 9 at 21:34
asked Nov 9 at 20:54
Bill
744411
744411
Have you tried NamedNativeQuery?
– AtulK
Nov 9 at 21:55
I also think that this is not possible with Spring Data JPA and even with JPA. You will have to write the query in SQL.
– Simon Martinelli
Nov 10 at 1:48
add a comment |
Have you tried NamedNativeQuery?
– AtulK
Nov 9 at 21:55
I also think that this is not possible with Spring Data JPA and even with JPA. You will have to write the query in SQL.
– Simon Martinelli
Nov 10 at 1:48
Have you tried NamedNativeQuery?
– AtulK
Nov 9 at 21:55
Have you tried NamedNativeQuery?
– AtulK
Nov 9 at 21:55
I also think that this is not possible with Spring Data JPA and even with JPA. You will have to write the query in SQL.
– Simon Martinelli
Nov 10 at 1:48
I also think that this is not possible with Spring Data JPA and even with JPA. You will have to write the query in SQL.
– Simon Martinelli
Nov 10 at 1:48
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233144%2fcombining-two-spring-data-query-method-liststring-parameters%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you tried NamedNativeQuery?
– AtulK
Nov 9 at 21:55
I also think that this is not possible with Spring Data JPA and even with JPA. You will have to write the query in SQL.
– Simon Martinelli
Nov 10 at 1:48