Hibernate fail to register REF_CURSOR parameter

3.2k views Asked by At

I am new to Hibernate. Using the 5.2.10 FINAL version connecting to Oracle 11g using the Oracle10gDialect with JPA 2.1 and ojdbc8.jar

I try to access a simple stored procedure taking a String input parameter and output a Oracle SYS_REFCURSOR.

StoredProcedureQuery call = session.createStoredProcedureCall("sp_get_profile");
call.registerStoredProcedureParameter(1, String.class, ParameterMode.IN);
call.registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR); 
call.execute();

An exception occur when I access the function

ERROR SqlExceptionHelper Invalid column type: 2012
DatabaseException::error=[Error registering REF_CURSOR parameter [2]]

I try to write a simple program connecting to DB with the Oracle Driver only. I will have the same error if I register Types.REF_CUSOR as the output parameter to CallableStatement.

cs.registerOutParameter(2, Types.REF_CURSOR);

And the problem can be solved by changing to OracleTypes

cs.registerOutParameter(2, OracleTypes.CURSOR);

Anyone know what is wrong? I need to fall back to use the traditional SQL programming if I cannot get the stored procedure access success. . . please help.

2

There are 2 answers

0
Ivan On

Finally got it work, I should check the Oracle JDBC document first before implementation.

ojdbc8 should be good for Oracle 12c + JDK8 + JPA2.1 with Oracle12cDialect.

For Oracle 11g, need to use ojdbc6.jar

0
Antonio Petricca On

I solved that issue by debugging OJDBC and Hibernate, the building from sources a patched Hibernate CORE library (5.4.15-Final).

I have patched the method ExtractedDatabaseMetaDataImpl.supportsRefCursors which returns always false.