Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling stored procedure using OUT parameter with Spring Spring JPA 2.*

I am calling a stored procedure using IN parameter - it's working fine.

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

Need help how to do it for OUT parameters.

like image 804
Mukti Avatar asked May 06 '16 18:05

Mukti


3 Answers

Refer below link for how to call a stored procedure.

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

like image 67
NIrav Modi Avatar answered Nov 11 '22 16:11

NIrav Modi


Simply define method annnotating it with Stored Procedure name, Map input param of stored Procedure with method parameters, Map output param of SP as the return type of the method, Example.

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

}

like image 1
Vikky Avatar answered Nov 11 '22 16:11

Vikky


You can use @Procedure used on a repository

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

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

I had to use the outputParameterName --> cause it was giving me an out undefined column error.

like image 1
cabaji99 Avatar answered Nov 11 '22 15:11

cabaji99