Issue
A query for a stored procedure for multiple delete yield an error message shown way below.
CREATE OR REPLACE PROCEDURE delete_dim_page(_page_id bigint)
LANGUAGE plpgsql
AS $procedure$
begin
delete from page_catalog where page_type_id = _page_id;
delete from page_type where page_type_id = _page_id;
END;
$procedure$
;
//entityclass
@NamedStoredProcedureQuery(
name = "firstProcedure",
procedureName = "delete_dim_page",
parameters = {
@StoredProcedureParameter(
mode=ParameterMode.IN,
name="_page_id",
type = Long.class
)
}
)
//service.java
StoredProcedureQuery query = em.createNamedStoredProcedureQuery("firstProcedure");
query.setParameter("_page_id", pageTypeId);
query.execute();
yields
ERROR: delete_dim_page1(bigint) is a procedure
Hint: To call a procedure, use CALL.
What is a recommendable way to call a stored procedure in Spring Boot?
Solution
I suppose yiu are using spring data jpa. You can just create a jpa repository et call your procedure with a annontation like that :
public interface PageCatalogRepository extends JpaRepository<PageCatalogEntity , Long> {
@Query(value = "CALL firstProcedure(:page_id);", nativeQuery = true)
void deletePageCatalogById(@Param("page_id") Long page_id);
}
You can find other procedure calling method here https://www.baeldung.com/spring-data-jpa-stored-procedures
Answered By - soung
Answer Checked By - Marie Seifert (JavaFixing Admin)