Package org.hibernate.procedure
First a reference to ProcedureCall
is obtained through one of the overloaded
SharedSessionContract.createStoredProcedureCall(java.lang.String)
methods. The ProcedureCall reference is then used to "configure"
the procedure call (set timeouts, etc) and to perform parameter registration. All procedure parameters that the
application wants to use must be registered. For all IN and INOUT parameters, values can then be bound.
At this point we are ready to execute the procedure call and start accessing the outputs. This is done by first
calling the ProcedureCall.getOutputs()
} method. The underlying JDBC call is executed as needed. The pattern to
access the returns is iterating through the outputs while Outputs.goToNext()
} returns true
and
calling Outputs.getCurrent()
} during iteration:
ProcedureCall call = session.createStoredProcedureCall( "some_procedure" );
...
ProcedureOutputs outputs = call.getOutputs();
while ( outputs.goToNext() ) {
final Output output = outputs.getCurrent();
if ( output.isResultSet() ) {
handleResultSetOutput( (ResultSetOutput) output );
}
else {
handleUpdateCountOutput( (UpdateCountOutput) output );
}
}
Finally, output parameters can be accessed using the overloaded ProcedureOutputs.getOutputParameterValue(org.hibernate.query.procedure.ProcedureParameter<T>)
methods.
For portability amongst databases, it is advised to access the output parameters after all returns have been
processed.
-
Interface Summary Interface Description FunctionReturn<T> Describes the function return for ProcedureCalls that represent calls to a function ("{? = call ...}
syntax) rather that a proc ({call ...}
syntax)ProcedureCall Defines support for executing database stored procedures and functions.ProcedureOutputs Specialization of theOutputs
contract providing access to the stored procedure's registered output parameters. -
Exception Summary Exception Description NamedParametersNotSupportedException Thrown to indicate that an attempt was made to register a stored procedure named parameter, but the underlying database reports to not support named parameters.NoSuchParameterException ParameterMisuseException Thrown to indicate a misuse of a parameterParameterStrategyException