Unable to resolve Oracle CURSOR JDBC type code: org.hibernate.HibernateException: Unable to access OracleTypes.CURSOR value in

JDK 1.8, Hibernate 5.2.16, Oracle 11g, ojdbc6

Creating stored procedure:

CREATE OR REPLACE PROCEDURE procCursorExample(
cursorParam OUT SYS_REFCURSOR, lastNameParam IN VARCHAR2)
IS
BEGIN

  OPEN cursorParam FOR
  SELECT * FROM PERSONS WHERE LAST_NAME = lastNameParam;

END;

Using named-stored-procedure-query parameter to define an stored procedure such as below:

<named-stored-procedure-query name="procCursorExample" procedure-name="procCursorExample">
        <parameter class="java.lang.String" name="lastNameParam" mode="IN"/>
        <parameter class="java.lang.Class" name="cursorParam" mode="REF_CURSOR"/>
</named-stored-procedure-query>

Calling an Oracle stored procedure with an OUT parameter of type SYS_REFCURSOR such as the below:

StoredProcedureQuery query = em.createNamedStoredProcedureQuery("procCursorExample");
query.setParameter("lastNameParam", "petrov");
query.registerStoredProcedureParameter("cursorParam", Class.class, ParameterMode.REF_CURSOR);
query.getResultList();

Encountering java.lang.ClassNotFoundException: oracle.jdbc.OracleTypes when executing a stored procedure query:

.

.. WARN  [org.hibernate.dialect.OracleTypesHelper] ... Unable to resolve Oracle CURSOR JDBC type code: org.hibernate.HibernateException: Unable to access OracleTypes.CURSOR value
...
Caused by: org.hibernate.HibernateException: Unable to locate OracleTypes class using either known FQN [oracle.jdbc.OracleTypes, oracle.jdbc.driver.OracleTypes]
...
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.OracleTypes from [Module "org.hibernate:main" from local module loader ...]
...
... DEBUG [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] ... Error asking dialect to register ref cursor parameter ...: java.sql.SQLException: Invalid column type: -99

This has nothing to do with Hibernate, but your application class loaders. Just make sure the Oracle JDBC Driver is made available to the application runtime. As you are using Wildfly, you should ask this question on the Wildfly forum as they can better help you with this problem.

For those that will reach this page from a search engine:

Yes it’s a class loading issue, but it will not help a lot telling to make the class available while it’s in the very same JAR (ojdbc6 in this case) as the Driver class used to acquire the connection… and obv. to reach statement execution point, the connection was successful…

https://hibernate.atlassian.net/browse/HHH-3449

Look first at a potential JAR conflict problem (old Oracle driver JAR had not the OracleTypes visible).