In Hibernate 4.2 I try to call stored procedure that returns cursor (I use Oracle DB).
Procedure looks like:
PROCEDURE SYS_columnNames ( ownerIn in sys.all_tab_cols.owner%type,
tableName in sys.all_tab_cols.table_name%type,
resultCur out curRef )
is
begin
open resultCur for
select column_name from sys.all_tab_cols
where owner = ownerIn
and Upper(Trim(table_name)) = tableName
order by column_name;
exception
when others then
null;
end SYS_columnNames ;
And my Java code:
Session session = null;
try
{
SessionFactory sessionFactory = sessionFactoryManager.getCurrentSession();
session = sessionFactory.openSession();
return session.doReturningWork( new ReturningWork< T >()
{
@SuppressWarnings( "unchecked" )
@Override
public T execute( Connection aConnection ) throws SQLException
{
CallableStatement callstm = null;
try
{
String functionCall = "{call " + aProcedureName + "(:owner, :tableName, :rescur)}";
callstm = aConnection.prepareCall( functionCall );
callstm.setString( "owner", "MYOWNER" );
callstm.setString( "tableName", "USER_TABLE" );
callstm.registerOutParameter( "rescur", OracleTypes.CURSOR );
callstm.execute();
return (T)callstm.getObject( 3 );
}
finally
{
closeQuietly( callstm );
}
}
} );
}
finally
{
closeQuietly( session );
}
But this give me an error:
org.hibernate.exception.GenericJDBCException: error executing work
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork(JdbcCoordinatorImpl.java:289)
at org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:1953)
at org.hibernate.internal.SessionImpl.doReturningWork(SessionImpl.java:1949)
(...)
Caused by: java.sql.SQLException: operation not allowed: Ordinal binding and Named binding cannot be combined!
at oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:2027)
at oracle.jdbc.driver.OracleCallableStatementWrapper.getObject(OracleCallableStatementWrapper.java:816)
at org.hibernate.jdbc.WorkExecutor.executeReturningWork(WorkExecutor.java:72)
at org.hibernate.internal.SessionImpl$3.accept(SessionImpl.java:1946)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork(JdbcCoordinatorImpl.java:284)
... 58 more
I totally don't know how to call stored procedure that returns cursor. Any help will be appreciated.