title: A CallableStatement function was executed and the out parameter 1 was of type java.sql.Types=2001 however type java.sql.Types=1111 was registered
body: <p>I am trying to call a STORED PROCEDURE(with a out refcursor parameter) in postgresql through JPA2.1 like this:</p>
  
  <pre><code>public class JpaINParam {
  
      public static void main(String[] args) throws Exception {
  
          EntityManagerFactory emfactory = Persistence
                  .createEntityManagerFactory("JPA2");
          EntityManager entitymanager = emfactory.createEntityManager();
          entitymanager.getTransaction().begin();
  
  
          StoredProcedureQuery q = entitymanager.createNamedStoredProcedureQuery("get_hibernate_dtl");
  
          q.setParameter("modeval", "1");
          q.execute();
  
          @SuppressWarnings("unchecked")
          List&lt;Student&gt; students = (List&lt;Student&gt;) q.getOutputParameterValue("resultset");
  
          for (Student student : students) {
              System.out.println(student.getFname());    
          }           
  
          entitymanager.getTransaction().commit();
          entitymanager.close();
  
          try {
              // storedProcedure.executeUpdate(); 
              System.out.println("444444444444");
          } catch (Exception e) {
              e.printStackTrace();
          }               
      }    
  }
  </code></pre>
  
  <p>i get the following error:</p>
  
  <blockquote>
  <pre><code>Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services -
  </code></pre>
    
    <p>2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
        Internal Exception: org.postgresql.util.PSQLException: A CallableStatement function was executed and the out parameter 1 was of
    type java.sql.Types=2001 however type java.sql.Types=1111 was
    registered.
        Error Code: 0
        Call: {?= CALL get_hibernate_dtl(?)}
          bind => [2 parameters bound]
        Query: ResultSetMappingQuery(name="get_hibernate_dtl" )
          at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:378)
          at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
          at org.eclipse.persistence.internal.jpa.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:316)
          at com.javacodegeeks.examples.jpa.service.JpaINParam.main(JpaINParam.java:36)</p>
  </blockquote>
  
  <p>the following is my entity class:</p>
  
  <pre><code>@NamedStoredProcedureQuery(name="get_hibernate_dtl", procedureName="get_hibernate_dtl", resultClasses={Student.class}, returnsResultSet = true, parameters={
          @StoredProcedureParameter(queryParameter="resultset", name="resultset", mode=ParameterMode.REF_CURSOR,type=Class.class),
          @StoredProcedureParameter(queryParameter="modeval", name="modeval", mode=ParameterMode.IN,type=String.class)
  
  
          })
  
  @Entity
  public class Student {
       @Id
       @GeneratedValue(strategy= GenerationType.AUTO)
       private int sid;
       private String fname;
       private String lname;
       private String dept;
       private int year;
       private String email;
  
      public Student() {
          // TODO Auto-generated constructor stub
      }
  
      public Student(int sid, String fname, String lname, String dept, int year,
              String email) {
          super();
          this.sid = sid;
          this.fname = fname;
          this.lname = lname;
          this.dept = dept;
          this.year = year;
          this.email = email;
      }
  
  
  
      public int getSid() {
          return sid;
      }
  
      public void setSid(int sid) {
          this.sid = sid;
      }
  
      public String getFname() {
          return fname;
      }
  
      public void setFname(String fname) {
          this.fname = fname;
      }
  
      public String getLname() {
          return lname;
      }
  
      public void setLname(String lname) {
          this.lname = lname;
      }
  
      public String getDept() {
          return dept;
      }
  
      public void setDept(String dept) {
          this.dept = dept;
      }
  
      public int getYear() {
          return year;
      }
  
      public void setYear(int year) {
          this.year = year;
      }
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }   
  
      @Override
      public String toString() {
          return "Student [sid=" + sid + ", fname=" + fname + ", lname=" + lname
                  + ", dept=" + dept + ", year=" + year + ", email=" + email
                  + "]";
      }       
  }
  </code></pre>
  
  <p>this is my procedure in postgresql:</p>
  
  <pre><code>CREATE OR REPLACE PROCEDURE dwh.get_hibernate_dtl(resultset OUT ahis_type.refcursor, modeval IN character varying DEFAULT '1'::character varying) AS
        query   VARCHAR2 (6000);
        v_type  NUMERIC(3,0);
        v_dwh_type_id VARCHAR2(100);
  
     BEGIN
  
           IF (modeval = 1) THEN
  
                  QUERY := ' SELECT sid,fname FROM STUDENT ';
  
             END IF;           
  
          INSERT INTO tmp_table values ( 'get_hibernate_dtl----Modeval--&gt;'||modeval||'query---&gt;'||QUERY );
  
        OPEN resultset FOR QUERY;
  
     END
  </code></pre>