我尝试以下代码:
ProcedureCall call = ss.createStoredProcedureCall("servicos.CLASSIFIER_MAP");
call.registerParameter( 1, String.class, ParameterMode.IN).bindValue(classifierString);
call.registerParameter( 2, Long.class, ParameterMode.IN ).bindValue(totalRows);
有时变量 totalRows 为空并出现错误
WARN: SQL Error: 17041, SQLState: 99999
Error calling CallableStatement.getMoreResults
可以在 hibernate 中将空值发送到 ProcedureCall 吗?
最佳答案
目前有两种方法可以实现您的目标:
param_null_passing
在您的 hibernate 配置中为 true。<property name="hibernate.proc.param_null_passing">true</property>
这是一个全局设置,可让您将空值传递给 ProcedureCall
在整个应用程序中。ProcedureCall call = ss.createStoredProcedureCall("servicos.CLASSIFIER_MAP");
call.registerParameter( 1, String.class, ParameterMode.IN).bindValue(classifierString);
call.registerParameter( 2, Long.class, ParameterMode.IN ).enablePassingNulls(true);
call.setParameter(2, totalRows);
来自 Hibernate 5 documentation :
hibernate.proc.param_null_passing(默认值为false):
Global setting for whether null parameter bindings should be passed to database procedure/function calls as part of ProcedureCall handling. Implicitly Hibernate will not pass the null, the intention being to allow any default argument values to be applied.
This defines a global setting, which can then be controlled per parameter via org.hibernate.procedure.ParameterRegistration#enablePassingNulls(boolean)
Values are true (pass the NULLs) or false (do not pass the NULLs).
关于java - ProcedureCall 中的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39922446/