Lajosh is right about the demotion. The problem is that you are coding under the assumption that the Output returned by ProcedureOutputs.getCurrent() will be ResultSetOutput , when in fact it could be UpdateCountOutput .
In fact, the Output interface has an isResultSet() method that helps you determine that:
boolean org.hibernate.result.Output.isResultSet ()
Determine if this return is a result (with the ability to click on ResultSetOutput ). An alternative is that this is the number of updates (with the ability to click on UpdateCountOutput ).
Return:
true indicates that this can be safely attributed to ResultSetOutput ), otherwise it can be distinguished to UpdateCountOutput .
In addition to this, Outputs can transmit multiple Outputs , and the state of Output.getCurrent() controlled by Output.goToNext() .
So, in order to handle multiple results correctly, you should get the output something like this:
ProcedureOutputs outputs = procedureCall.getOutputs(); do { Output current = outputs.getCurrent(); if (current.isResultSet()) { ResultSetOutput resultSetOutput = (ResultSetOutput) current; System.out.println("do something with result set output"); } else { UpdateCountOutput updateCountOutput = (UpdateCountOutput) current; System.out.println("do something with update count output"); } } while (outputs.goToNext()); outputs.release();
In my tests, I get:
1647 [main] DEBUG org.hibernate.SQL - {call p_getTeamTasksForLastXDays (?,?)}
Sleep mode: {call p_getTeamTasksForLastXDays (?,?)}
1668 [main] DEBUG org.hibernate.result.internal.OutputsImpl - Building Return [isResultSet = false, updateCount = 0, extendedReturn = false
do something with an update counter
1669 [main] DEBUG org.hibernate.result.internal.OutputsImpl - Building Return [isResultSet = true, updateCount = -1, extendedReturn = false
1671 [main] DEBUG org.hibernate.loader.Loader - result set string: 0
1671 [main] DEBUG org.hibernate.loader.Loader - result line:
do something with result set result
PS: I donβt have mysql here, so I canβt confirm if it returns both ResultSetOutput and UpdateCountOutput , but in a different order than hsqldb, but maybe you can check it.