Spring jdbc : simplejdbcall doesn't read metadata for parameters when executing stored procedure using synonym

标签 spring oracle jdbc

我正在尝试使用 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 ”过程存在于“ USER ”包下的名为“ USER_DATA _0x100”的模式中我在另一个名为“ USER_SCH ”的模式中为同一个包/过程创建了一个同义词。当我使用 simpleJDBCCall.execute() 方法执行代码时,它不会读取元数据并抛出以下执行。
    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.ADD_ADDRESS”存在的情况下使用模式名称“USER_DATA”执行相同的代码,那么它会正确读取元数据信息并执行该过程。

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

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

最佳答案

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

关于 Spring jdbc : simplejdbcall doesn't read metadata for parameters when executing stored procedure using synonym,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26240045/

相关文章:

oracle - 如何获取包 oracle 中所有过程的列表

java - JDBC架构子系统

spring - 如何从 Spring 中对 Websphere 应用服务器中定义的 MQ 连接工厂进行 jndi 查找

spring - spring webflux 中的文件上传 - 所需的 MultipartFile 参数 'file' 不存在

sql - 甲骨文 : renaming a key in a json field by oracle

java - resultset是否直连数据库

java - 使用 MVC 和 DAO 模式在 JSP 页面的 HTML 中显示 JDBC ResultSet

java - Spring:新建和 Autowiring :新建的对象可以永远不使用 Autowiring 吗?

java - 如何从 Spring MVC 获取当前使用的区域设置?

sql - INSERT 语句上的 "Not a valid month"