I have a function I created in my PostgreSQL DB that I want to call using JPA 2.1\'s StoredProcedureQuery method.
Here is my PostgreSQL query:
CREA
Short answer: Reverse the order of your two calls to registerStoredProcedureParameter()
:
storedProcedure.registerStoredProcedureParameter(1, Object.class, ParameterMode.REF_CURSOR);
storedProcedure.registerStoredProcedureParameter(2, String.class, ParameterMode.IN);
Long answer: I did some digging in the Hibernate source code for Postgress callable statement support, and found that each registerStoredProcedureParameter()
call creates a ParameterRegistrationImplementor instance that gets tacked into a list and passed around. You'll note that this class stores the position of the parameter, which is independent of its position within the list.
Later, this list is analyzed and assumes that the REF_CURSOR
parameter will be first in line, and throws your error message if a REF_CURSOR
parameter is not first, regardless of what the parameter number is.
Not a very bright way of doing things (IMHO), but at least the workaround is easy: if you swap the order of your calls, you should be fine.