<!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;"> </p><p>This is oracle stored procedure.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>CREATE PROCEDURE SP_SELECT_ORA (</p><p>  ID_INPUT IN VARCHAR2,</p><p>  ID_OUTPUT OUT VARCHAR2,</p><p>  PASSWD_OUTPUT OUT VARCHAR2,</p><p>  NAME_OUTPUT OUT VARCHAR2) IS</p><p>BEGIN</p><p>       SELECT EMP_ID, EMP_Passwd, EMP_Name</p><p>       INTO ID_OUTPUT, PASSWD_OUTPUT, NAME_OUTPUT</p><p>       FROM   family</p><p>       WHERE  EMP_ID = ID_INPUT;</p><p>END;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>And I call the SP in NamedNativeQuery like below</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>Members.java</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>@NamedNativeQueries({</p><p>    @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;"> </p><p>    @Id</p><p>    @Column(name = "EMP_ID")</p><p>    private String ID;</p><p>    </p><p>    @Column(name = "EMP_Passwd")</p><p>    private String Passwd;</p><p>    </p><p>    @Column(name = "EMP_Name")</p><p>    private String Name;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>CallStoredProcedureBean.java</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>@Stateless</p><p>public class CallStoredProcedureBean implements ICallStoredProcedurePort {</p><p>    </p><p>    @PersistenceContext(unitName="MyFamily")</p><p>    EntityManager em;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    @Override</p><p>    public Object callSP(String type, String ID) {</p><p>        // TODO Auto-generated method stub</p><p>        Query query = null;</p><p>        Members member = null;</p><p>        </p><p>        query = em.createNamedQuery("callSelectSP");</p><p>        query.setParameter(1, ID);</p><p>        ////////////////////</p><p>        //  <strong>I don't know how to call stored procedure....</strong></p><p>        ///////////////////</p><p>        query.executeUpdate();</p><p>        member = (Members)query.getSingleResult();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        System.out.println("Flash !!");</p><p>        </p><p>        return member;</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </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>