我正在将 EclipseLink 用于涉及 EJB 3 和 Oracle 存储过程的 Web 项目。我们还处于起步阶段,所以我设置了一个简单的测试程序,这是签名:
p_test.testProcedure(as_param in varchar2)
这是我用来调用该过程的代码,类似于 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);
我不断收到此错误:
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()
我还尝试将调用参数类型设置为 java.sql.Types.VARCHAR,但根本没有设置,但没有效果。
有人知道我做错了什么吗?谢谢大家。
最佳答案
看起来您在 addNamedArgument 方法中指定的 procedureParameterName 与存储过程中指定的不同,即“param”与“as_param”。尝试将您的逻辑更改为以下内容:
call.addNamedArgument("as_param", "param", String.class);
此方法在调用 query.addParameter 时使用的参数名称与存储过程中定义的参数名称之间进行映射。
关于java - EclipseLink:调用存储过程的参数数量或类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5067235/