【问题标题】:Calling stored procedure using OUT parameter with Spring Spring JPA 2.*使用 Spring Spring JPA 2.* 使用 OUT 参数调用存储过程
【发布时间】:2016-05-06 18:44:20
【问题描述】:

我正在使用 IN 参数调用存储过程 - 它工作正常。

public interface ABCRepository extends JpaRepository<ABC, Integer> {
    @Query(nativeQuery=true, value="exec p_NextSequence :clazName , 1")
    Integer  callSequenceForClaz(@Param ("clazName")String clazName);
}

需要帮助如何处理 OUT 参数。

【问题讨论】:

    标签: java spring spring-data spring-data-jpa


    【解决方案1】:

    如何调用存储过程请参考以下链接。

    https://dzone.com/articles/calling-stored-procedures-from-spring-data-jpa

    【讨论】:

      【解决方案2】:

      只需定义使用存储过程名称注释它的方法,将存储过程的输入参数映射到方法参数,将SP的输出参数映射为方法的返回类型,示例。

      @Repository
      public interface EmployeeJPA extends JpaRepository<Employee, Long> {
      @Procedure(procedureName = "enroll_employee_program")
      public String enrollEmpProgram(Long employeeId, Long programId,  LocalDate createdDate, String createdBy);
      

      }

      【讨论】:

        【解决方案3】:

        您可以使用在存储库上使用的@Procedure

        @Procedure(procedureName="SP_MP_LOG_CONSULTA",outputParameterName="response")
        

        int call(@Param("name") name);

        我不得不使用 outputParameterName --> 因为它给了我一个未定义的列错误。

        【讨论】:

          猜你喜欢
          • 2021-03-15
          • 2020-09-22
          • 1970-01-01
          • 2015-07-26
          • 2017-07-20
          • 2021-09-02
          • 1970-01-01
          • 2018-01-03
          • 1970-01-01
          相关资源
          最近更新 更多