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