Unable to get the returned value while calling Stored Procedure from JPA












0















The SP looks like:-



CREATE PROCEDURE <spnamegoeshere>
AS
BEGIN
/* Some code goes here */
return 102323 /*Need to get this value*/
END
GO


We are executing a Stored Procedure (hosted in SQL SERVER), through JPA using



createStoredProcedureQuery("spnamegoeshere");


I need to get that returned value "102323". Unfortunatly, using above command, unable to get.



After searching a bit, got this link.



https://docs.microsoft.com/en-us/sql/connect/jdbc/using-a-stored-procedure-with-a-return-status?view=sql-server-2017



As per the above doc, I can able to get the value, if I use .



CallableStatement


Any way to do the same using the JPA, without modifying the SP?



Could someone share some input here.










share|improve this question























  • Don't use RETURN. Use an OUTPUT parameter.

    – Larnu
    Nov 23 '18 at 11:58











  • @Larnu: Hi, Thx for the reply. Yes. But I should not modify the SP because of constraints. Any way to achieve without it?

    – NANDAKUMAR
    Nov 23 '18 at 12:00











  • Here's an idea ... present your code about HOW you are using and invoking StoredProcedureQuery. Docs for it explain very clearly how to get return values. datanucleus.org:15080/products/accessplatform_5_2/jpa/…

    – Billy Frost
    Nov 23 '18 at 13:28
















0















The SP looks like:-



CREATE PROCEDURE <spnamegoeshere>
AS
BEGIN
/* Some code goes here */
return 102323 /*Need to get this value*/
END
GO


We are executing a Stored Procedure (hosted in SQL SERVER), through JPA using



createStoredProcedureQuery("spnamegoeshere");


I need to get that returned value "102323". Unfortunatly, using above command, unable to get.



After searching a bit, got this link.



https://docs.microsoft.com/en-us/sql/connect/jdbc/using-a-stored-procedure-with-a-return-status?view=sql-server-2017



As per the above doc, I can able to get the value, if I use .



CallableStatement


Any way to do the same using the JPA, without modifying the SP?



Could someone share some input here.










share|improve this question























  • Don't use RETURN. Use an OUTPUT parameter.

    – Larnu
    Nov 23 '18 at 11:58











  • @Larnu: Hi, Thx for the reply. Yes. But I should not modify the SP because of constraints. Any way to achieve without it?

    – NANDAKUMAR
    Nov 23 '18 at 12:00











  • Here's an idea ... present your code about HOW you are using and invoking StoredProcedureQuery. Docs for it explain very clearly how to get return values. datanucleus.org:15080/products/accessplatform_5_2/jpa/…

    – Billy Frost
    Nov 23 '18 at 13:28














0












0








0








The SP looks like:-



CREATE PROCEDURE <spnamegoeshere>
AS
BEGIN
/* Some code goes here */
return 102323 /*Need to get this value*/
END
GO


We are executing a Stored Procedure (hosted in SQL SERVER), through JPA using



createStoredProcedureQuery("spnamegoeshere");


I need to get that returned value "102323". Unfortunatly, using above command, unable to get.



After searching a bit, got this link.



https://docs.microsoft.com/en-us/sql/connect/jdbc/using-a-stored-procedure-with-a-return-status?view=sql-server-2017



As per the above doc, I can able to get the value, if I use .



CallableStatement


Any way to do the same using the JPA, without modifying the SP?



Could someone share some input here.










share|improve this question














The SP looks like:-



CREATE PROCEDURE <spnamegoeshere>
AS
BEGIN
/* Some code goes here */
return 102323 /*Need to get this value*/
END
GO


We are executing a Stored Procedure (hosted in SQL SERVER), through JPA using



createStoredProcedureQuery("spnamegoeshere");


I need to get that returned value "102323". Unfortunatly, using above command, unable to get.



After searching a bit, got this link.



https://docs.microsoft.com/en-us/sql/connect/jdbc/using-a-stored-procedure-with-a-return-status?view=sql-server-2017



As per the above doc, I can able to get the value, if I use .



CallableStatement


Any way to do the same using the JPA, without modifying the SP?



Could someone share some input here.







sql-server jpa stored-procedures spring-data-jpa spring-data






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 11:57









NANDAKUMARNANDAKUMAR

2341416




2341416













  • Don't use RETURN. Use an OUTPUT parameter.

    – Larnu
    Nov 23 '18 at 11:58











  • @Larnu: Hi, Thx for the reply. Yes. But I should not modify the SP because of constraints. Any way to achieve without it?

    – NANDAKUMAR
    Nov 23 '18 at 12:00











  • Here's an idea ... present your code about HOW you are using and invoking StoredProcedureQuery. Docs for it explain very clearly how to get return values. datanucleus.org:15080/products/accessplatform_5_2/jpa/…

    – Billy Frost
    Nov 23 '18 at 13:28



















  • Don't use RETURN. Use an OUTPUT parameter.

    – Larnu
    Nov 23 '18 at 11:58











  • @Larnu: Hi, Thx for the reply. Yes. But I should not modify the SP because of constraints. Any way to achieve without it?

    – NANDAKUMAR
    Nov 23 '18 at 12:00











  • Here's an idea ... present your code about HOW you are using and invoking StoredProcedureQuery. Docs for it explain very clearly how to get return values. datanucleus.org:15080/products/accessplatform_5_2/jpa/…

    – Billy Frost
    Nov 23 '18 at 13:28

















Don't use RETURN. Use an OUTPUT parameter.

– Larnu
Nov 23 '18 at 11:58





Don't use RETURN. Use an OUTPUT parameter.

– Larnu
Nov 23 '18 at 11:58













@Larnu: Hi, Thx for the reply. Yes. But I should not modify the SP because of constraints. Any way to achieve without it?

– NANDAKUMAR
Nov 23 '18 at 12:00





@Larnu: Hi, Thx for the reply. Yes. But I should not modify the SP because of constraints. Any way to achieve without it?

– NANDAKUMAR
Nov 23 '18 at 12:00













Here's an idea ... present your code about HOW you are using and invoking StoredProcedureQuery. Docs for it explain very clearly how to get return values. datanucleus.org:15080/products/accessplatform_5_2/jpa/…

– Billy Frost
Nov 23 '18 at 13:28





Here's an idea ... present your code about HOW you are using and invoking StoredProcedureQuery. Docs for it explain very clearly how to get return values. datanucleus.org:15080/products/accessplatform_5_2/jpa/…

– Billy Frost
Nov 23 '18 at 13:28












1 Answer
1






active

oldest

votes


















0














This works for me:



  @Test
public void testProc() {
SimpleJdbcCall call = new SimpleJdbcCall(jdbcTemplate);
Map<String, Object> map = call.withProcedureName("retValTestProc").withReturnValue().execute();
Assert.assertNotNull("Expected not null result but it is", Objects.nonNull(map));
Assert.assertTrue("Expected size = 1, actual=" + map.size(), map.size() == 1);
Assert.assertTrue("Expected value=102323, actual=" + map.get("RETURN_VALUE"),
Objects.equals(102323, map.get("RETURN_VALUE")));
}


Where retValTestProc = <spnamegoeshere>



Also you can create a SimpleJdbcCall with a DataSource constructor






share|improve this answer
























  • Hi @yuriy: any methods from entitymanager (jpa) instead of jdbc comands. In question to I suggested the same. Any idea? Thx

    – NANDAKUMAR
    Nov 23 '18 at 13:04













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',
autoActivateHeartbeat: false,
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%2f53446288%2funable-to-get-the-returned-value-while-calling-stored-procedure-from-jpa%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














This works for me:



  @Test
public void testProc() {
SimpleJdbcCall call = new SimpleJdbcCall(jdbcTemplate);
Map<String, Object> map = call.withProcedureName("retValTestProc").withReturnValue().execute();
Assert.assertNotNull("Expected not null result but it is", Objects.nonNull(map));
Assert.assertTrue("Expected size = 1, actual=" + map.size(), map.size() == 1);
Assert.assertTrue("Expected value=102323, actual=" + map.get("RETURN_VALUE"),
Objects.equals(102323, map.get("RETURN_VALUE")));
}


Where retValTestProc = <spnamegoeshere>



Also you can create a SimpleJdbcCall with a DataSource constructor






share|improve this answer
























  • Hi @yuriy: any methods from entitymanager (jpa) instead of jdbc comands. In question to I suggested the same. Any idea? Thx

    – NANDAKUMAR
    Nov 23 '18 at 13:04


















0














This works for me:



  @Test
public void testProc() {
SimpleJdbcCall call = new SimpleJdbcCall(jdbcTemplate);
Map<String, Object> map = call.withProcedureName("retValTestProc").withReturnValue().execute();
Assert.assertNotNull("Expected not null result but it is", Objects.nonNull(map));
Assert.assertTrue("Expected size = 1, actual=" + map.size(), map.size() == 1);
Assert.assertTrue("Expected value=102323, actual=" + map.get("RETURN_VALUE"),
Objects.equals(102323, map.get("RETURN_VALUE")));
}


Where retValTestProc = <spnamegoeshere>



Also you can create a SimpleJdbcCall with a DataSource constructor






share|improve this answer
























  • Hi @yuriy: any methods from entitymanager (jpa) instead of jdbc comands. In question to I suggested the same. Any idea? Thx

    – NANDAKUMAR
    Nov 23 '18 at 13:04
















0












0








0







This works for me:



  @Test
public void testProc() {
SimpleJdbcCall call = new SimpleJdbcCall(jdbcTemplate);
Map<String, Object> map = call.withProcedureName("retValTestProc").withReturnValue().execute();
Assert.assertNotNull("Expected not null result but it is", Objects.nonNull(map));
Assert.assertTrue("Expected size = 1, actual=" + map.size(), map.size() == 1);
Assert.assertTrue("Expected value=102323, actual=" + map.get("RETURN_VALUE"),
Objects.equals(102323, map.get("RETURN_VALUE")));
}


Where retValTestProc = <spnamegoeshere>



Also you can create a SimpleJdbcCall with a DataSource constructor






share|improve this answer













This works for me:



  @Test
public void testProc() {
SimpleJdbcCall call = new SimpleJdbcCall(jdbcTemplate);
Map<String, Object> map = call.withProcedureName("retValTestProc").withReturnValue().execute();
Assert.assertNotNull("Expected not null result but it is", Objects.nonNull(map));
Assert.assertTrue("Expected size = 1, actual=" + map.size(), map.size() == 1);
Assert.assertTrue("Expected value=102323, actual=" + map.get("RETURN_VALUE"),
Objects.equals(102323, map.get("RETURN_VALUE")));
}


Where retValTestProc = <spnamegoeshere>



Also you can create a SimpleJdbcCall with a DataSource constructor







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 12:48









Yuriy TsarkovYuriy Tsarkov

765420




765420













  • Hi @yuriy: any methods from entitymanager (jpa) instead of jdbc comands. In question to I suggested the same. Any idea? Thx

    – NANDAKUMAR
    Nov 23 '18 at 13:04





















  • Hi @yuriy: any methods from entitymanager (jpa) instead of jdbc comands. In question to I suggested the same. Any idea? Thx

    – NANDAKUMAR
    Nov 23 '18 at 13:04



















Hi @yuriy: any methods from entitymanager (jpa) instead of jdbc comands. In question to I suggested the same. Any idea? Thx

– NANDAKUMAR
Nov 23 '18 at 13:04







Hi @yuriy: any methods from entitymanager (jpa) instead of jdbc comands. In question to I suggested the same. Any idea? Thx

– NANDAKUMAR
Nov 23 '18 at 13:04




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446288%2funable-to-get-the-returned-value-while-calling-stored-procedure-from-jpa%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

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...