Using the new JPA 2.1 stored procedure call, is there any way to pass a null parameter?
Here is an example usage:
StoredProcedureQuery storedProcedur
Yes, it is possible to pass null params to stored procedures when using JPA StoredProcedureQuery.
You have to add the following property in application.properties file and register the parameters with their name.
spring.jpa.properties.hibernate.proc.param_null_passing=true
Example:
StoredProcedureQuery q = em.createStoredProcedureQuery(Globals.SPROC_PROBLEM_COMMENT2, ProblemCommentVO.class);
q.registerStoredProcedureParameter("Patient_ID", Long.class, ParameterMode.IN);
q.registerStoredProcedureParameter("Param2", Long.class, ParameterMode.IN);
q.registerStoredProcedureParameter("Param3", Long.class, ParameterMode.IN);
q.registerStoredProcedureParameter("Param4", Integer.class, ParameterMode.OUT);
q.setParameter("Patient_ID", patientId);
q.setParameter("Param2", null);//passing null value to Param2
q.setParameter("Param3", null);
List pComments = q.getResultList();
Integer a = (Integer) q.getOutputParameterValue("Param4");