Getting ref cursor from a SP is working when we use query.getResultList();
StoredProcedureQuery query = entityManager.createNamedStoredProcedureQuery("extractWebUser");
query.setParameter(1, userId);
query.setParameter(2, period);
query.setParameter(3, idClientLimit);
query.execute();
*List resultList = query.getResultList();*
But when we try to get parameter by position or name, hibernate is throwing exception.
Object outputParameterValue = query.getOutputParameterValue(4);
org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.java
...
...
public T extract(CallableStatement statement) {
...
else if ( mode == ParameterMode.REF_CURSOR ) {
throw new ParameterMisuseException( "REF_CURSOR parameters should be accessed via results" );
}
...
From section 3.10.17.3 Stored Procedure Query Execution of the JPA2.1 spec:
When using REF_CURSOR parameters for result sets, the update counts should be exhausted before calling getResultList to retrieve the result set. Alternatively, the REF_CURSOR result set can be retrieved through getOutputParameterValue. Result set mappings will be applied to results corresponding to REF_CURSOR parameters in the order the REF_CURSOR parameters were registered with the query.
|