我有一个具有2个输出参数varchar2和ref_cursor的过程
PROCEDURE login_check (id_in IN edit_users.userid%TYPE,
password_in IN edit_users.usr_password%TYPE,
status_out OUT VARCHAR2,
cur_out OUT SYS_REFCURSOR
)
我定义了一个namedStoredProcedureQuery
@NamedStoredProcedureQuery(name = "login_check",
procedureName = "edit_maintenance.login_check",
parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name ="id_in",type = String.class),
@StoredProcedureParameter(mode = ParameterMode.IN, name ="password_in",type = String.class),
@StoredProcedureParameter(mode = ParameterMode.OUT, name ="status_out",type = String.class),
@StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, name ="cur_out", type = void.class)
})
当我通过storedProcedureQuery调用此过程时,可以获取“ status_out”,但在调用getResultList方法时却出现了空点异常。
StoredProcedureQuery storedProcedureQuery = em.createNamedStoredProcedureQuery("login_check");
storedProcedureQuery.setParameter("id_in",username);
storedProcedureQuery.setParameter("password_in",password);
storedProcedureQuery.execute();
String status = (String)storedProcedureQuery.getOutputParameterValue("status_out");
System.out.println(status);
List<UserTo> userToList = storedProcedureQuery.getResultList();
return userToList.get(0);
ava.lang.NullPointerException
at org.hibernate.loader.custom.JdbcResultMetadata.<init>(JdbcResultMetadata.java:32)
at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:476)
at org.hibernate.result.internal.OutputsImpl$CustomLoaderExtension.processResultSet(OutputsImpl.java:285)
at org.hibernate.result.internal.OutputsImpl.extractResults(OutputsImpl.java:136)
at org.hibernate.procedure.internal.ProcedureOutputsImpl.access$500(ProcedureOutputsImpl.java:26)
at org.hibernate.procedure.internal.ProcedureOutputsImpl$ProcedureCurrentReturnState.lambda$buildExtendedReturn$0(ProcedureOutputsImpl.java:95)
at org.hibernate.result.internal.ResultSetOutputImpl.getResultList(ResultSetOutputImpl.java:41)
at org.hibernate.procedure.internal.ProcedureCallImpl.getResultList(ProcedureCallImpl.java:756)
at com.schenker.editrade.repository.UserRepositoryImpl.loginCheck(UserRepositoryImpl.java:23)
at com.schenker.editrade.repository.UserRepositoryImpl$$FastClassBySpringCGLIB$$61af36ef.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
答案 0 :(得分:0)
看起来您正在获得此异常,因为缺少光标输出的元数据。您可以尝试将适当的Java类型用于光标输出,而不是“ void.class”。
根据文档here,游标可以映射到以下Java类型之一:
例如,您可以尝试以下方式:
@StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, name ="cur_out", type = java.sql.ResultSet.class)