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?










share|improve this question























  • 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














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?










share|improve this question























  • 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












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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20