首页 文章

spring jdbc:simplejdbcall在使用同义词执行存储过程时不读取参数的元数据

提问于
浏览
3

我正在尝试使用simpleJDBCCall.excute(in)方法执行存储过程,但在使用过程的同义词时,它不会读取元数据 .

这是代码 .

SimpleJdbcCall optOutCall = new SimpleJdbcCall(dataSource)
        .withSchemaName("USER_SCH")
        .withCatalogName("USER")
        .withProcedureName(ADD_ADDRESS) 
        .declareParameters(
                new SqlOutParameter("returnCode", Types.NUMERIC),
                new SqlParameter("product_id", Types.NUMERIC),
                new SqlParameter("user_id", Types.NUMERIC),
                new SqlParameter("email_address", Types.VARCHAR));
    long returnCode = 0;
    inputs.addValue("returnCode", returnCode);
    inputs.addValue("product_id", 1);
    inputs.addValue("user_id", 45673);
    inputs.addValue("email_address", "a.b@abc.com");

    optOutCall.execute(inputs);

这里“ ADD_ADDRESS " procedure exist under " USER " package in a schema called " USER_DATA ". I have created a synonym for the same package/procedure in another schema called " USER_SCH ” . 当我使用simpleJDBCCall.execute()方法执行代码时,它不读取元数据并抛出以下execption .

Caused by: java.sql.SQLException: ORA-06550: line 1, column 7:PLS-00306: wrong number or types of arguments in call to 'ADD_ADDRESS'ORA-06550: line 1, column 7:PL/SQL: Statement ignored

这是日志消息 .

[07 Oct 2014 10:32:49,019] [DEBUG] [org.springframework.jdbc.core.simple.SimpleJdbcCall]: [JdbcCall call not compiled before execution - invoking compile]
[07 Oct 2014 10:32:49,019] [DEBUG] [org.springframework.jdbc.datasource.DataSourceUtils]: [Fetching JDBC Connection from DataSource]
[07 Oct 2014 10:32:49,020] [DEBUG] [org.springframework.jdbc.core.metadata.CallMetaDataProviderFactory]: [Using org.springframework.jdbc.core.metadata.OracleCallMetaDataProvider]
[07 Oct 2014 10:32:49,020] [DEBUG] [org.springframework.jdbc.core.metadata.CallMetaDataProvider]: [Retrieving metadata for USER/USER_SCH/ADD_ADDRESS]
[07 Oct 2014 10:32:49,028] [DEBUG] [org.springframework.jdbc.datasource.DataSourceUtils]: [Returning JDBC Connection to DataSource]
[07 Oct 2014 10:32:49,028] [DEBUG] [org.springframework.jdbc.core.simple.SimpleJdbcCall]: [Compiled stored procedure. Call string is [{call USER.ADD_ADDRESS()}]]
[07 Oct 2014 10:32:49,028] [DEBUG] [org.springframework.jdbc.core.simple.SimpleJdbcCall]: [SqlCall for procedure [ADD_ADDRESS] compiled]
[07 Oct 2014 10:32:49,028] [DEBUG] [org.springframework.jdbc.core.metadata.CallMetaDataContext]: [Matching [returnCode, product_id, user_id,email_address] with []]
[07 Oct 2014 10:32:49,028] [DEBUG] [org.springframework.jdbc.core.metadata.CallMetaDataContext]: [Found match for []]
[07 Oct 2014 10:32:49,028] [DEBUG] [org.springframework.jdbc.core.simple.SimpleJdbcCall]: [The following parameters are used for call {call USER.ADD_ADDRESS()} with: {}]
[07 Oct 2014 10:32:49,028] [DEBUG] [org.springframework.jdbc.core.JdbcTemplate]: [Calling stored procedure [{call USER.ADD_ADDRESS()}]]
[07 Oct 2014 10:32:49,028] [DEBUG] [org.springframework.jdbc.datasource.DataSourceUtils]: [Fetching JDBC Connection from DataSource]
[07 Oct 2014 10:32:49,034] [DEBUG] [org.springframework.jdbc.datasource.DataSourceUtils]: [Returning JDBC Connection to DataSource]
[07 Oct 2014 10:32:49,034] [DEBUG] [org.springframework.jdbc.support.SQLErrorCodesFactory]: [Looking up default SQLErrorCodes for DataSource [weblogic.jdbc.common.internal.RmiDataSource@2521ddb8]]
[07 Oct 2014 10:32:49,034] [DEBUG] [org.springframework.jdbc.support.SQLErrorCodesFactory]: [SQLErrorCodes found in cache for DataSource [weblogic.jdbc.common.internal.RmiDataSource@2521ddb8]]
[07 Oct 2014 10:32:49,035] [DEBUG] [org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator]: [Unable to translate SQLException with Error code '6550', will now try the fallback translator]
[07 Oct 2014 10:32:49,035] [DEBUG] [org.springframework.jdbc.support.SQLStateSQLExceptionTranslator]: [Extracted SQL state class '65' from value '65000']
[07 Oct 2014 10:32:49,035] [ WARN] [gproducterr]: [Handler execution resulted in exception]
org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar [{call USER.ADD_ADDRESS()}]; nested exception is java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'ADD_ADDRESS'ORA-06550: line 1, column :PL/SQL: Statement ignored

但是如果我使用模式名称“USER_DATA”执行相同的代码,其中存在此过程“USER.ADD_ADDRESS”,则它会正确读取元数据信息并执行该过程 .

我正在使用的用户具有“USER_SCH.USER.ADD_ADDRESS”过程的执行权限 .

在使用同义词执行任何过程时,我需要做什么改变才能正确读取元数据?

2 回答

  • 0

    添加“.withoutProcedureColumnMetaDataAccess();” . 它将停止 spring 读取jdbc元数据,并将使用您提供的详细信息 . 有用 .

  • 6

    您无法为打包的过程/函数创建同义词 . 您可以为:创建同义词:

    • 表或对象表

    • 视图或对象视图

    • 序列

    • 存储过程,函数或包

    • 物化视图

    • Java类架构对象

    • 用户定义的对象类型

    • 同义词

    因此,您可以为包创建一个同义词,但是您仍然需要通过其声明的名称来引用包中的过程/函数/任何内容 .

    Reference here

    分享和享受 .

相关问题