Mukti
Mukti

Reputation: 311

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.

Upvotes: 6

Views: 30470

Answers (4)

Eduardo Ju&#225;rez
Eduardo Ju&#225;rez

Reputation: 1

Encontre este ejemplo que me funciono, saludos @Procedure(procedureName = "con_nombreSP", outputParameterName = "out_parameter") public double nameMethod (@Param ("in_param") double param, @Param ("in_param2") double param2, @Param ("in_param3") int param3);

Upvotes: 0

cabaji99
cabaji99

Reputation: 1445

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.

Upvotes: 1

Vikky
Vikky

Reputation: 1233

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);

}

Upvotes: 1

NIrav Modi
NIrav Modi

Reputation: 6962

Refer below link for how to call a stored procedure.

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

Upvotes: 3

Related Questions