title: Hibernate 4 - Call stored procedure having IN as well as OUT parameters
body: <p>I researched much about how to call stored procedure using hibernate 4 session object with In &amp; OUT params, but no use. </p>
  
  <p>Finally got a clue related to the "SessionImpl". Using this object we can get the Connection object.</p>
  
  <p>Using this connection object can call the prepareCall() method, which will support the IN/OUT params of the procedure.</p>
  
  <p>Following is a sample snippet.</p>
  
  <pre><code>        Map&lt;String, String&gt; returnMap = new HashMap&lt;String, String&gt;(); 
          Session session = sessionFactory.getCurrentSession();
          Connection connObj = ((SessionImpl)session).connection();
          CallableStatement connStmt = connObj.prepareCall("{ call SCHEMA.PKG_NAME.SP_NAME(?,?,?) }");
          connStmt.setLong(1, 123456);
  
          connStmt.registerOutParameter(2, java.sql.Types.VARCHAR);
          connStmt.registerOutParameter(3, java.sql.Types.VARCHAR);
          connStmt.execute();
  
          if(connStmt != null &amp;&amp; connStmt.getString(2).equalsIgnoreCase("Y")) {
              returnMap.put("returnID", ExceptionConstants.SUCCESS_STATUS);
              returnMap.put("returnMessage", connStmt.getString(3));  
          } else {
              returnMap.put("returnID", ExceptionConstants.FAILED_STATUS);
              returnMap.put("returnMessage", connStmt.getString(3));
          }
  </code></pre>