I have a mapped stored procedure
<sql-query name="sproc" callable="true" >
<return alias="suppliers" class="model.Supplier">
<return-property name="name" column="CoName" />
</return>
{ call sproc(:p1,:p2,:p3}
</sql-query>
When executed as a named query and the stored procedure returns results then query.list() will return the expected results but when the stored procedure returns no results I get a NPE when Hibernate is trying to initialize the entity to return.
I could catch the npe and return an empty list but that’s not great, is there anything else I can do?
According to this hibernate docs the mssql stored procedure must return a result set. Further in section 16.2.2.1 it states you can use session.connection(). But I don’t think that will be of much use. Hence handling the null pointer seems a good way.
EDIT :
If you are using
session.connection(), you can also return the@@ROWCOUNTif the output is the only thing that is being used in the procedure to get the number of rows changed. 0 indicating nothing being returned