Skip to content
Advertisement

`Type cannot be null` exception when trying to run out Stored Procedure using Spring Data JPA

I am trying to invoke a Stored Procedure whose signature looks like the following:

JavaScript

I am using Spring-Data JPA and have tried a number of different variants, but all of them follow more or less the following pattern. My entity model is decorated as follows:

JavaScript

Then I have my repository which looks like the following:

JavaScript

I have followed the instructions from quite a few examples, but I am always left with the same error, namely:

JavaScript

Any ideas what is wrong here?

Advertisement

Answer

I was not able to get this syntax working as such, however, the notion of retrieving from a stored procedure is effectively a shorthand for selecting from (possibly a view) mixed with applying some input based function. To that effect, I have replaced my stored procedure with a function / table that yields the same effect.

JavaScript

This uses the @Query syntax in conjunction with a table and a function, whose overall logic is identical to calling the stored procedure I had intended. Although a little more difficult to follow perhaps, the syntax is at least much shorter than using the @NamedStoredProcedureQuery.

The function does the same thing the stored procedure originally did EXCEPT for the last part which was a SELECT INTO, this is now encapsulated as part of the @Query.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement