We're updating the issue view to help you get more done. 

Implement REF_CURSOR support for StoredProcedureQuery.getOutputParameterValue(4);

Description

Getting ref cursor from a SP is working when we use query.getResultList();

1 2 3 4 5 6 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.

1 Object outputParameterValue = query.getOutputParameterValue(4);

org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.java

1 2 3 4 5 6 7 8 ... ... 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:

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.

Environment

None

Status

Assignee

Vlad Mihalcea

Reporter

Vishnudev K

Fix versions

Labels

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.1.8

Priority

Major