Am a bit confused, am trying to call a stored procedures using spring boot JPA. Have created a simple procedure and call the procedure using JPA’s @NamedStoredProcedureQuery annotation.
For some wierd reason am getting an error
Parameter emp_name was not defined for stored procedure get_empoyee_details. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError
what am i doing wrong, have tried to go through other answers on stackoverflow no help
this is my entity class
import lombok.Data;
import lombok.ToString;
@Entity
@Data
@ToString
@NamedStoredProcedureQuery(name = "get_empoyee_details", procedureName = "get_empoyee_details", resultClasses = {
Employee.class }, parameters = {
@StoredProcedureParameter(name = "emp_name", mode = ParameterMode.IN, type = String.class) })
public class Employee {
@Id
@GeneratedValue
private Long id;
@Column(name = "designation")
private String designation;
@Column(name = "employee_name")
private String employeeName;
@Column(name = "employee_code")
private String employeeCode;
}
my controller
@RestController
public class EmployeeController {
@PersistenceContext
private EntityManager entityManager;
@SuppressWarnings("unchecked")
@GetMapping("/employees")
public ResponseEntity<List<Employee>> getEmp(@RequestParam(name = "name") String name) {
List<Employee> employees = entityManager.createNamedStoredProcedureQuery("get_empoyee_details")
.setParameter("emp_name", name).getResultList();
return new ResponseEntity<>(employees, HttpStatus.OK);
}
}
thank you in advance
stack trace
Error preparing registered callable parameter] with root cause
com.microsoft.sqlserver.jdbc.SQLServerException: Parameter emp_name was not defined for stored procedure get_empoyee_details.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:234) ~[mssql-jdbc-8.2.2.jre8.jar:na]
my stored procedure for sql server
CREATE PROCEDURE get_empoyee_details @name nvarchar(30)
AS
SELECT *
FROM employee
WHERE employee_name = @name
GO
The parameter name is wrong as the excpetion says.
com.microsoft.sqlserver.jdbc.SQLServerException:
Parameter emp_name was not defined forstored procedure get_empoyee_details.
Change it to name:
@NamedStoredProcedureQuery(name = "get_empoyee_details",
procedureName = "get_empoyee_details",
resultClasses = { Employee.class },
parameters = {
@StoredProcedureParameter(name = "name", // this was wrong
mode = ParameterMode.IN, type = String.class) })
public class Employee {