I am calling a procedure from Spring Boot. Getting following exception:
java.lang.IllegalArgumentException: Named parameter [B] is not registered with this procedure call
I have this entity class:
@Entity
@NamedStoredProcedureQuery(name = NamedStoredProcedure.MyProc, procedureName = Procedures.MyProc, resultClasses = MyProcResult.class, parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = ParameterName.A, type = String.class),
@StoredProcedureParameter(mode = ParameterMode.IN, name = ParameterName.B, type = String.class)
})
public class CallProc{
.
.
}
I am sending required parameters:
StoredProcedureQuery publishedSessionStoredProcedure = entityManager.createNamedStoredProcedureQuery(NamedStoredProcedure.MyProc);
publishedSessionStoredProcedure.setParameter(ParameterName.A, a);
publishedSessionStoredProcedure.setParameter(ParameterName.B, b);
In procedure, also same no and type of parameters are expected.
What can be the reason ?
I had the same exact issue, I chose to use 'createStoredProcedureQuery' instead of 'createNamedStoredProcedureQuery'
Try adding these lines:
.registerStoredProcedureParameter(ParameterName.A, String.class, ParameterMode.IN)
.registerStoredProcedureParameter(ParameterName.B, String.class, ParameterMode.IN)
Then your code should look something like this:
StoredProcedureQuery publishedSessionStoredProcedure = entityManager.createStoredProcedureQuery(NamedStoredProcedure.MyProc, MyProcResult.class)
.registerStoredProcedureParameter(ParameterName.A, String.class, ParameterMode.IN)
.registerStoredProcedureParameter(ParameterName.B, String.class, ParameterMode.IN);
publishedSessionStoredProcedure.setParameter(ParameterName.A, a);
publishedSessionStoredProcedure.setParameter(ParameterName.B, b);
For me registering the parameter did the trick hope it'll work for you 2
P.S. I also had to add SqlResultSetMapping for my object (in your case MyProcResult)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With