title: Invalid column name exception when calling an Oracle stored procedure with ref_cursor through JPA 2.1
body: <p>I am trying to execute an Oracle stored procedure using JPA. I am able to retrieve results if I build the query and call the stored procedure through the query.getResultList() as shown below:</p>
  
  <pre><code>    @Autowired
      EntityManager em;
      public List&lt;MyEntity&gt; callStoredProcedure(String paramOneValue, String paramTwoValue)
     {
          StoredProcedureQuery query = em.createStoredProcedureQuery("storedProcedureName");
          query.registerStoredProcedureParameter("paramOneName", String.class, ParameterMode.IN);
          query.registerStoredProcedureParameter("paramTwoName", String.class, ParameterMode.IN);
          query.registerStoredProcedureParameter("results", Void.class, ParameterMode.REF_CURSOR);
          query.setParameter("paramOneName", paramOneValue);
          query.setParameter("paramTwoName", paramTwoValue);
  
          query.execute();
  
          List&lt;MyEntity&gt; result = new ArrayList&lt;MyEntity&gt;();  
  
          for(Object item: query.getResultList())
          {
              /* mapping my object to the entity and adding to the collection
              result.add(new MyEntity(item));
          }
  
          return result;
      }
  </code></pre>
  
  <p>However, this is not very elegant.</p>
  
  <p>If I try to use the entity mapping as in the code below, I get an errpr </p>
  
  <blockquote>
    <p>org.springframework.orm.jpa.JpaSystemException: Error extracting results from CallableStatement" </p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>java.sql.SQLException: Invalid column name</p>
  </blockquote>
  
  <p>after the procedure is called and when is trying to map to the entity</p>
  
  <pre><code>     @NamedStoredProcedureQueries({
   @NamedStoredProcedureQuery(name = "MyStoredProcedure", 
          procedureName = "storedProcedureName",
          resultClasses = {MyEntity.class}, 
          parameters = { 
              @StoredProcedureParameter(name = "paramOneName", mode = ParameterMode.IN, type = String.class),
              @StoredProcedureParameter(name = "paramTwoName", mode = ParameterMode.IN, type = String.class),
              @StoredProcedureParameter(name = "results", mode = ParameterMode.REF_CURSOR, type = void.class)
          })
   })
   @Entity
   public class MyEntity implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue
      private long id;
      @Column(name="MY_FIRST_COLUMN")
      private String myFirstColumn;
      // Related Properties
   }
   // And declaring as repository
   @Repository
   public interface IMyRepository extends JpaRepository&lt;MyEntity, Long  {
      @Procedure
      List&lt;MyEntity  callMyStoredProcedure(@Param("paramOneName") String paramOneName, 
                                          @Param("paramTwoName") String paramTwoName);    
   }
  </code></pre>
  
  <p>I tried to solve this issue in several ways, using entity custom mapping
  @SqlResultSetMapping and also trying cast the <code>query.getResultList</code> to the <code>List&lt;MyEntity&gt;</code>. However the exception is always the same.</p>
  
  <p>It looks like JPA is unable to get the column information from the stored procedure.</p>
  
  <p>I double checked the column names and they match the columns retrieved by the stored procedure, however it must be added that there isn't a real table with such columns in the database.</p>
  
  <p>From the pom...</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
          &lt;version&gt;1.0.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
          &lt;version&gt;5.2.2.Final&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p><em>Does the stored procedure need to be written in a specific way in order for the mapping to work (PS unfortunately I don't have access to the stored procedure definition)?</em></p>
  
  <p><em>Do I need a physical table or view in the database with the same column as the one retrieved by the stored procedure, in order to be able to map the resultset to an entity?</em></p>
  
  <p>Thanks a lot for your help</p>