title: Getting select statement results from a stored procedure using JPA?
body: <p>Using JPA, I'm calling a MS SQL Server 2008 R2 stored procedure that looks like this</p>
  
  <pre><code>procedure [dbo].[testProc]
      @param1 varchar(max),
      @param2 datetime
  as
  begin
  EXEC sessionProc
  
  DECLARE @reportData varbinary(max)
  
  EXEC aThirdPartyProc
       @reportData out,
       @parameter1 = @param1,
       @date = @param2
  
  SELECT col1, col2
  FROM fFunction(@reportData)
  
  end
  </code></pre>
  
  <p>When trying to get the results from the select statement</p>
  
  <pre><code>StoredProcedureQuery q = em.createNamedStoredProcedureQuery("reportData");
  q.setParameter("param1", "val1");
  q.setParameter("param2", new Date());
  return (List&lt;ReportData&gt;) q.getResultList();
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>java.lang.IllegalStateException: Current CallableStatement ou was not a ResultSet, but getResultList was called
      at org.hibernate.jpa.internal.StoredProcedureQueryImpl.getResultList(StoredProcedureQueryImpl.java:319)
  </code></pre>
  
  <p><strong>How can I get the select statement results?</strong> </p>
  
  <p>Note: The JPA code works if I reduce testProc to a simple select (remove the two EXEC statements).</p>
  
  <p>Also, here's the ReportData entity class:</p>
  
  <pre><code>@Entity
  @NamedStoredProcedureQuery(name = "reportData", procedureName = "testProc", resultClasses = ReportData.class, parameters = {
          @StoredProcedureParameter(mode = ParameterMode.IN, name = "param1", type = String.class),
          @StoredProcedureParameter(mode = ParameterMode.IN, name = "param2", type = Date.class)
            })
  public class ReportData {
      @Id
      private String col1;
      private String col2;
      // getter and setter for col1 and col2
  }
  </code></pre>
  
  <p>I've tested the proc in SQL Server Management Studio and it works fine returning results from the select statement.</p>