Call Stored Procedures using Spring Boot JPA | Code Factory

Reference Link : Link

Donate : Link

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.codeFactory</groupId>
<artifactId>spring-boot-call-stored-procedures</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-call-stored-procedures</name>
<description>Demo project for Spring Boot Call Stored Procedure</description>

application.properties

spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root

SpringBootCallStoredProceduresApplication.java

package com.codeFactory;

EmployeeController.java

package com.codeFactory.controller;

Employee.java

package com.codeFactory.model;

EmployeeRepository.java

package com.codeFactory.repository;

EmployeeRepositoryCustom.java

package com.codeFactory.repository;

EmployeeRepositoryImpl.java

package com.codeFactory.repository;

EmployeeService.java

package com.codeFactory.service;

Create Table 'employee' :

CREATE TABLE `employee` (
`id` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`salary` bigint(20) NOT NULL,
PRIMARY KEY (`id`)
);

Procedure 'FIND_EMP_BY_ID' :

CREATE DEFINER=`root`@`localhost` PROCEDURE `FIND_EMP_BY_ID`(in p_id int)
BEGIN
SELECT id, name, salary
FROM employee
WHERE id = p_id;
END