简体   繁体   English

EclipseLink:调用存储过程的参数数目或类型错误

[英]EclipseLink: Wrong number or types of arguments calling a Stored Procedure

I'm using EclipseLink for a web project involving EJB 3 and Oracle stored procedures. 我正在将EclipseLink用于涉及EJB 3和Oracle存储过程的Web项目。 We're still in the beginning, so I had a simple procedure set up for testing, here's the signature: 我们仍处于起步阶段,因此我为测试设置了一个简单的过程,这是签名:

p_test.testProcedure(as_param in varchar2)

Here's the code I use to call the procedure, similar to the Using Basic Query API article on Eclipsepedia: 这是我用来调用该过程的代码,类似于Eclipsepedia上的《使用基本查询API》一文:

JpaEntityManager jem = (JpaEntityManager) em.getDelegate();

StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("p_test.testProcedure");

call.addNamedArgument("param", "param", String.class);

DataReadQuery query = new DataReadQuery();
query.setCall(call);

query.addArgument("param", String.class);

Vector<String> values = new Vector<String>();
values.add("test");

jem.getActiveSession().executeQuery(query, values);

I keep getting this error: 我不断收到此错误:

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.1.v20100817-r8050):
org.eclipse.persistence.exceptions.DatabaseException Internal Exception: 
java.sql.SQLException: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of 
arguments in call to 'TESTPROCEDURE' ORA-06550: line 1, column 7: PL/SQL: Statement
ignored Error Code: 6550 Call: BEGIN p_test.testProcedure(param=>?); END; bind => [test] Query: DataReadQuery()

I also have tried setting call argument type to java.sql.Types.VARCHAR and none at all, to no effect. 我也尝试将调用参数类型设置为java.sql.Types.VARCHAR,并且完全没有设置,这毫无作用。

Someone have any ideas what am I doing wrong? 有人知道我在做什么错吗? Thanks everyone. 感谢大家。

It looks like you are specifying a different procedureParameterName in the addNamedArgument method than what is specified in your stored procedure, ie, "param" vs "as_param". 似乎您在addNamedArgument方法中指定的过程参数名称与存储过程中指定的过程参数名称不同,即“ param”与“ as_param”。 Try changing your logic to the following: 尝试将逻辑更改为以下内容:

call.addNamedArgument("as_param", "param", String.class);

This method maps the parameter name between what is used in your call to query.addParameter and what is defined in the stored procedure. 此方法将参数名称映射到您对query.addParameter的调用中使用的参数与存储过程中定义的参数之间。

From TopLink docs 来自TopLink文档

addNamedArgument addNamedArgument

public void addNamedArgument(java.lang.String procedureParameterName,
                             java.lang.String argumentFieldName)

PUBLIC: Define the argument to the stored procedure and the field/argument name to be substitute for it. PUBLIC:定义存储过程的参数和要替换的字段/参数名称。 The procedureParameterName is the name of the procedure argument expected. procedureParameterName是所需过程参数的名称。 The argumentFieldName is the field or argument name to be used to pass to the procedure. argumentsFieldName是用于传递给过程的字段或参数名称。 If these names are the same (as they normally are) this method can be called with a single argument. 如果这些名称相同(通常相同),则可以使用单个参数调用此方法。

public void addNamedArgumentValue(java.lang.String procedureParameterName,
                                  java.lang.Object argumentValue)

 call.addNamedArgumentValue("param",(Object)values );

Solved using a combination of the above two answers and my own wits. 通过结合以上两个答案和我自己的智慧来解决。

First, I used addNamedArgumentValue asu suggested by #1. 首先,我使用了#1建议的addNamedArgumentValue asu。 Second, I used the correct procedure parameter name as suggested by #2. 其次,我使用了#2建议的正确的过程参数名称。 Last, I used directly jem.executeNonSelectingCall(call) and it worked. 最后,我直接使用了jem.executeNonSelectingCall(call) ,它可以正常工作。 (Also with OUT parameters). (还有OUT参数)。

So they both get a vote up! 这样他们俩都可以投票了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM