Java Spring:无法确定正确的调用签名-多个过程/函数/签名

Java Spring:无法确定正确的调用签名-多个过程/函数/签名,java,spring,oracle,stored-procedures,Java,Spring,Oracle,Stored Procedures,我正在尝试从Oracle存储过程获取数据。问题是,在我们的数据库中,有一个函数和一个过程具有相同的名称和参数 当我试着称之为: @Autowired public void setDataSource (@Qualifier("dataSource") DataSource dataSource) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.setResu

我正在尝试从Oracle存储过程获取数据。问题是,在我们的数据库中,有一个函数和一个过程具有相同的名称和参数

当我试着称之为:

@Autowired
    public void setDataSource (@Qualifier("dataSource") DataSource dataSource) {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        jdbcTemplate.setResultsMapCaseInsensitive(true);
        this.functionGetSomeCode = new SimpleJdbcCall(jdbcTemplate)
                .declareParameters(new SqlOutParameter("RETURN", OracleTypes.NUMBER))
                .withFunctionName("get_some_code").withSchemaName("XXX").withCatalogName("some_pkg");
    }

    public Integer getSomeCode (String incoming) {
        SqlParameterSource incomingParameters = new MapSqlParameterSource().addValue("incoming", incoming);
        return functionGetSomeCode.executeFunction(Integer.class, incomingParameters);
    }
我得到一个例外:

springframework.dao.InvalidDataAccessApiUsageException: Unable to determine the correct call signature - multiple procedures/functions/signatures

有没有一种方法可以在不要求DBA将函数/过程重命名为其他名称的情况下处理这种情况?

我能够调用具有相同名称但并不总是有效的函数和过程。 在您的示例中,看起来您没有声明输入参数。尝试使用与包声明尽可能匹配的类型声明输入和输出参数。如果仍然不起作用,您可以尝试关闭ProcedureClumNMetadataAccess,但一定要进行测试

以下是一个例子:

protected SimpleJdbcCall buildJdbcCall(JdbcTemplate jdbcTemplate) {
    SimpleJdbcCall call = new SimpleJdbcCall(jdbcTemplate)
            .withSchemaName(schema)
            .withCatalogName(catalog)
            .withFunctionName(functionName) 
            // can use withProcedureName(procedureName) for procedures 
            //.withReturnValue()
            //  .withoutProcedureColumnMetaDataAccess()  // may need this
            .declareParameters(buildSqlParameters());
    return call;
}

public SqlParameter[] buildSqlParameters() {
    return new SqlParameter[]{
        new SqlParameter("p_id", Types.VARCHAR),
        new SqlParameter("p_office_id", Types.VARCHAR),
        new SqlOutParameter("l_clob", Types.CLOB)
    };
}

如果您没有返回变量,下面的代码可以提供帮助。我面临着同样的问题,我的代码在没有声明out参数的情况下工作,因为函数没有out参数。我通过将out参数声明为return解决了这个问题。代码如下

SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate.getDataSource()).withCatalogName("PACKAGE_NAME")
                .withFunctionName("MY_FUNCTION_NAME").withoutProcedureColumnMetaDataAccess().declareParameters(
                        new SqlOutParameter("RETURN", Types.TIMESTAMP),
                        new SqlParameter("XYX_Y", Types.DATE),
                        new SqlParameter("HH_HDU", Types.VARCHAR)
                        );
        jdbcCall.compile();

        MapSqlParameterSource in = new MapSqlParameterSource();
        in.addValue("XYX_Y", myDate);
        in.addValue("HH_HDU", "PQR");
        java.sql.Timestamp date =  jdbcCall.executeFunction(java.sql.Timestamp.class, in);


我也面临同样的问题。我有两个同名的处理器,有一个不同的参数“lang_code_in”。看起来这个问题只是由于这个原因,它是因为Spring/Spring启动应用程序而出现的。所以我在“.WithOutProcedureRecolumnMetadataAccess()之后添加了

但在此之后,它开始给出以下错误: org.springframework.jdbc.BadSqlGrammarException:CallableStatementCallback;错误的SQL语法[{call NPIADM.CCM_JIGSAW_TEMPLATE_PKG.GET_UPC_XML_CONTENT(?,?)}];嵌套异常是java.sql.SQLException:ORA-06550:第1行第7列: PLS-00306:调用“获取UPC\U XML\U内容”时参数的数量或类型错误 ORA-06550:第1行第7列: PL/SQL:忽略语句

然后我添加了所有的in和out参数declareParameters()对象,如下所示,它开始正常工作。下面的代码有P_订单号_I在参数中,P_err_msg_o在参数外

public SqlParameter[] buildPullOrderSqlParameters() {
    return new SqlParameter[]{
            new SqlParameter("P_ORDER_NUMBER_I", Types.VARCHAR),
            new SqlOutParameter("p_err_msg_o", Types.VARCHAR)
    };
}

感谢您的输入,但是如果仔细研究代码,我的参数(in和out)将被声明。您将“传入”参数传递到executeFunction调用中,而不在declareParameters数组中声明它。
public SqlParameter[] buildPullOrderSqlParameters() {
    return new SqlParameter[]{
            new SqlParameter("P_ORDER_NUMBER_I", Types.VARCHAR),
            new SqlOutParameter("p_err_msg_o", Types.VARCHAR)
    };
}