<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    how to call oracle stored procedure?
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/aupres">Joseph Hwang</a> in <i>EJB3</i> - <a href="https://community.jboss.org/message/649396#649396">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I try to call oracle stored procedure from hibernate in JBoss as 7. My IDE is eclipse Indigo.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This is oracle stored procedure.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>CREATE PROCEDURE SP_SELECT_ORA (</p><p>&#160; ID_INPUT IN VARCHAR2,</p><p>&#160; ID_OUTPUT OUT VARCHAR2,</p><p>&#160; PASSWD_OUTPUT OUT VARCHAR2,</p><p>&#160; NAME_OUTPUT OUT VARCHAR2) IS</p><p>BEGIN</p><p>&#160;&#160;&#160;&#160;&#160;&#160; SELECT EMP_ID, EMP_Passwd, EMP_Name</p><p>&#160;&#160;&#160;&#160;&#160;&#160; INTO ID_OUTPUT, PASSWD_OUTPUT, NAME_OUTPUT</p><p>&#160;&#160;&#160;&#160;&#160;&#160; FROM&#160;&#160; family</p><p>&#160;&#160;&#160;&#160;&#160;&#160; WHERE&#160; EMP_ID = ID_INPUT;</p><p>END;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>And I call the SP in NamedNativeQuery like below</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>Members.java</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>@NamedNativeQueries({</p><p>&#160;&#160;&#160; @NamedNativeQuery(name = "callSelectSP", query = "CALL SP_SELECT_ORA(?,?,?,?)", resultClass = Members.class)</p><p>})</p><p>@Entity</p><p>@Table(name="family")</p><p>public class Members implements Serializable {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @Id</p><p>&#160;&#160;&#160; @Column(name = "EMP_ID")</p><p>&#160;&#160;&#160; private String ID;</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; @Column(name = "EMP_Passwd")</p><p>&#160;&#160;&#160; private String Passwd;</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; @Column(name = "EMP_Name")</p><p>&#160;&#160;&#160; private String Name;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>CallStoredProcedureBean.java</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>@Stateless</p><p>public class CallStoredProcedureBean implements ICallStoredProcedurePort {</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; @PersistenceContext(unitName="MyFamily")</p><p>&#160;&#160;&#160; EntityManager em;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @Override</p><p>&#160;&#160;&#160; public Object callSP(String type, String ID) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // TODO Auto-generated method stub</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Query query = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Members member = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; query = em.createNamedQuery("callSelectSP");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; query.setParameter(1, ID);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ////////////////////</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; //&#160; <strong>I don't know how to call stored procedure....</strong></p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ///////////////////</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; query.executeUpdate();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; member = (Members)query.getSingleResult();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Flash !!");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return member;</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I don't know how to handle out parameters in oracle SP.</p><p>Pls, advise me. Thanks in advanced !</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/649396#649396">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>