When calling a stored procedure with 1+ out REF_CURSOR’s, it fails to retrieve the rows when using getResultList().
Per the documentation, it mentions:
“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.”
The last sentence makes it seem as if repeat calls to .getResultList() will move the cursor to the next REF_CURSOR. However, that does not appear to be the cause.
The title mentions how Hibernate “fails” to, however - this might be totally intended.
You’re correct — and you’re not misunderstanding the Hibernate behavior.
Straight Answer:
Calling .getResultList()does not advance between multiple REF_CURSORs. It only retrieves the first cursor result, and trying to call it again will throw an error (like “ResultSet is closed”).
This is expected behavior in Hibernate, and not a bug. The documentation is subtle and easy to misread, but Hibernate requires that you manually retrieve each REF_CURSOR result using getOutputParameterValue(index).
Why this happens:
When you use .getResultList(), Hibernate internally assumes a single result set (the first REF_CURSOR).
Hibernate does not manage multiple cursors via multiple .getResultList() calls.
Attempting to call .getResultList() again after the first closes the cursor and results in the error you’re seeing.