Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to return the generated value of a stored procedure using hibernate
    primarykey
    data
    text
    <p>I am new to hibernate i got a scenario where i need to call a stored procedure using hibernate.I am using native query to call my stored procedure.The code below is where i am setting all the parameters to the stored proc.And i declared my query in my entity. </p> <pre><code>ENTITY class: @Entity @NamedNativeQueries({ @NamedNativeQuery( name = "callStoreProcedure", query = "CALL SP_INS_EPC_CERTIFICATE_EVENTS(:BUS_PARTNER_ID ,:PROVIDER_NAME,:PROVIDER_ADDR_LINE1,:PROVIDER_ADDR_LINE2 ,:PROVIDER_CITY,:PROVIDER_STATE,EPC_CERTIFICATE)", resultClass = DOEPCTest.class) }) </code></pre> <p>Stored procedure: </p> <pre><code>CREATE PROCEDURE EPRMTADM.SP_INS_EPC_CERTIFICATE_EVENTS ( -- IN EPC_CERTIFICATE_ID INTEGER, IN P_BUS_PARTNER_ID CHAR(6), IN P_PROVIDER_NAME VARCHAR(80), IN P_PROVIDER_ADDR_LINE1 VARCHAR(80), IN P_PROVIDER_ADDR_LINE2 VARCHAR(80), IN P_PROVIDER_CITY VARCHAR(80), IN P_PROVIDER_STATE CHAR(2), OUT P_EPC_CERTIFICATE_ID INTEGER ) </code></pre> <p>(....INSERT Statments which sets all the values in to the PROC)</p> <pre><code>SET P_EPC_CERTIFICATE_ID = IDENTITY_VAL_LOCAL(); </code></pre> <p>OUT P_EPC_CERTIFICATE_ID INTEGER returns the certificate_id</p> <pre><code>Query query = sessionFactory.getCurrentSession().getNamedQuery("callStoreProcedure"). setParameter("BUS_PARTNER_ID", "0123"); setParameter("PROVIDER_NAME", "qwe"); query.setParameter("PROVIDER_ADDR_LINE1", "asdasd"); query.setParameter("PROVIDER_ADDR_LINE2", "aasd"); query.setParameter("PROVIDER_CITY", "asd"); query.setParameter("PROVIDER_STATE", "pa"); List result = query.list(); </code></pre> <p>As my CERTIFICATE_ID is generated value i cannot set it,It is the return value.How can i handle it in hibernate.Is there any standard api which returns the OUT P_EPC_CERTIFICATE_ID INTEGER out</p> <p>And this is identity key generated by DB2 when i call this Store Procedure.Is there any way to get this certificate id out.I am able to set the parameters in but.I coudnt get this value out.I think i should pass some thing like.</p> <pre><code> procedure.registerOutParameter(EPC_CERTIFICATE_ID , java.sql.Types.INTEGER); </code></pre> <p>But i have no idea how to do it using Query in hibernate. please suggest a best way to get the identity get out. thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload