I am trying to invoke a parameter less stored procedure using the Spring Annotation @NamedStoredProcedureQuery.
Technology stack is Spring Data JPA with Hibernate, and database is Teradata.
It always fails saying "Procedure not found" because it tries to invoke as
call proc_name()
which is bound to fail.
However the right way to call the stored procedure is
call schemaName.proc_name()
I can't figure out a way to specify the schema name in the Entity that I have created.
@NamedStoredProcedureQuery(
name="proc_name",
procedureName="proc_name",
resultClasses = { Sc_Refresh.class }
)
@Entity
@Table(schema = "Schema_Name", name = "TEMP_TABLE" )
public class Sc_Refresh {
}
Can someone help?
Found out the solution.
In the Repo layer, wherein we are using @Procedure annotation, we should provide the fully qualified name for the procedure. Example,
@Repository
public interface Repo extends JpaRepository<Entity, Long>{
@Procedure("SCHEMA_NAME.PROC_NAME")
void explicitlyNamedProcName();
}
This approach worked for me.
@NamedStoredProcedureQuery(
name="procName",
procedureName="<schema_name>.proc_name"
)
@Entity
@Table
public class User {
...
}
Put the schema name before database procedure name in the procedureName annotation attribute name. Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With