Skip to content

Instantly share code, notes, and snippets.

@Francisco-Castillo
Last active July 31, 2021 18:56
Show Gist options
  • Save Francisco-Castillo/226258c524ce760ba4c99e280d504936 to your computer and use it in GitHub Desktop.
Save Francisco-Castillo/226258c524ce760ba4c99e280d504936 to your computer and use it in GitHub Desktop.
Spring boot stored procedure
CREATE OR REPLACE PROCEDURE student_leave(studentId number)
LANGUAGE plpgsql
AS $procedure$
begin
UPDATE student
SET status = 1 WHERE id = studentId;
end; $procedure$
;
@Repository
public interface StudentRepository extends JpaRepository<StudentEntity, Long> {
// ...
@Transactional
@Modifying
@Query(value = "CALL student_leave(:studentId);", nativeQuery = true)
public void studentLeave(@Param("studentId") Long studentId);
}
@Slf4j
@Service
public class StudentService {
@Autowired
private StudentRepository studentRepository;
public ResponseEntity<Object> update(Long studentId){
try{
// Ejecutamos el SP
studentRepository.studentLeave(studentId);
}catch(){
//...
}
}
}
@Francisco-Castillo
Copy link
Author

Ejecutar procedimiento almacenado en Spring boot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment