Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify Schema name while using @NamedStoredProcedureQuery

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?

like image 465
Kapil Malhotra Avatar asked Jan 29 '26 01:01

Kapil Malhotra


2 Answers

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();

}
like image 83
Kapil Malhotra Avatar answered Jan 30 '26 14:01

Kapil Malhotra


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.

like image 28
vzhemevko Avatar answered Jan 30 '26 15:01

vzhemevko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!