How to specify Schema name while using @NamedStoredProcedureQuery

僤鯓⒐⒋嵵緔 提交于 2019-12-11 10:12:07

问题


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?


回答1:


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

}



回答2:


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.



来源:https://stackoverflow.com/questions/34808904/how-to-specify-schema-name-while-using-namedstoredprocedurequery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!