title: Hibernate calling procedure having mutliple result set
body: <p>In my spring boot application I am connecting to mysql using hibernate. I have a database procedure which returns multiple result set.</p>
  
  <p><code>DELIMITER //
   CREATE PROCEDURE get_customer_meta()
     BEGIN
     SELECT area_code,description  FROM area;
     SELECT category_code,description  FROM category;
     END //
   DELIMITER ;</code></p>
  
  <p>As per <a href="https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querysql.html#sp_query" rel="nofollow noreferrer">hibernate documentation</a> which says </p>
  
  <p><code>You cannot use stored procedures with Hibernate unless you follow some procedure/function rules. If they do not follow those rules they are not usable with Hibernate. If you still want to use these procedures you have to execute them via session.connection().</code></p>
  
  <p><strong>As my requirement is something like this, (Multiple result set ) How can I achieve this with hibernate ?. How can I execute them via session.connection() as described in docs ?</strong> </p>
  
  <p>I have already tried using storedProcedureQuery but I get error <code>java.sql.SQLException: Column 'area_code' not found.</code> On this line in below code <code>List&lt;Object[]&gt; secondList = query.getResultList();</code>.</p>
  
  <pre><code>@Repository
  public class CustomerMetaDao {
  
      @PersistenceContext
      private EntityManager entityManager;
  
      public CustomerMetaModel getCustomerMetaData() {
          StoredProcedureQuery query = entityManager.createStoredProcedureQuery("get_customer_meta");
          List&lt;Object[]&gt; objList = query.getResultList();
          System.out.println(objList.get(0)[0]);
          System.out.println(objList.get(0)[1]);
          if (query.hasMoreResults()) {
              List&lt;Object[]&gt; secondList = query.getResultList();
              System.out.println(secondList.get(0)[0]);
              System.out.println(secondList.get(0)[1]);
          }
          return null;
      }
  }
  </code></pre>