What you are trying (handling INOUT / OUT parameters) is not supported in 4.1. Through 4.1 support, Hibernate called support focuses on returning a ResultSet. There is support for the fact that you are trying already at the place of the leading master and will be part of the next major version of Hibernate (which will be either 4.2 or 5.0); there, the calling functions / procedures are now a first class operation.
Now you need to either directly use JDBC or create Hibernate from master and use this new support. If you choose a later version, it will look like this:
StoredProcedureCall call = session.createStoredProcedureCall( "GET_VENDOR_STATUS_COUNT" ) .registerStoredProcedureParameter( "DOCUMENT_ID", Long.class, ParameterMode.IN ) .registerStoredProcedureParameter( "NOT_INVITED", String.class, ParameterMode.OUT ) ...; call.getRegisteredParameter( "DOCUMENT_ID" ).bindValue( theDocumentId ); StoredProcedureOutputs outputs = call.getOutputs(); String notInvited = (String) outputs.getOutputParameterValue( "NOT_INVITED" ); ...
This code is still young and is likely to change. For example, when I write these examples more often, I think that registerStoredProcedureParameter should be renamed as registerParameter or declareParameter and that it should return a typed representation of the declaration / registration; something like:
interface RegisteredParameter<T> { Class<T> getParameterType(); // only valid for IN or INOUT params void bindValue(T value); } <T> RegisteredParameter<T> registerParameter(String name, Class<T> type, ParameterMode mode);
which will then allow:
StoredProcedureCall call = session.createStoredProcedureCall( "GET_VENDOR_STATUS_COUNT" ) call.registerParameter( "DOCUMENT_ID", Long.class, ParameterMode.IN ).bindValue( theDocumentId ); RegisteredParameter<String> notInvitedParam = call.registerParameter( "NOT_INVITED", String.class, ParameterMode.OUT ); ... String notInvited = outputs.getOutputParameterValue( notInvitedParam );
As an added bonus, people trying to do this early can help shape what it looks like before it is released (at this point it is much harder to change).
Steve ebersole
source share