[英]EclipseLink - Oracle Stored Procedure call newbie problem
I'm in charge of a task which I believe should be simple, but as I never did it before I have some trouble with it. 我负责一项我认为应该很简单的任务,但是由于从未遇到过麻烦,因此我从未做过。 I have succesfully created an EJB 3 project using EclipseLink which will call a number of stored procedures from an Oracle database. 我已经使用EclipseLink成功创建了一个EJB 3项目,该项目将从Oracle数据库中调用许多存储过程。 I've configured the datasource correctly, I can connect and execute simple stored procedures and functions (without parameters and returning a cursor); 我已经正确配置了数据源,可以连接并执行简单的存储过程和函数(不带参数且不返回游标); however, I am currently unable to execute stored procedures with parameters. 但是,我目前无法执行带参数的存储过程。
I'm using the EclipseLink wiki as a reference http://wiki.eclipse.org/Using_Basic_Query_API_(ELUG ) . 我使用EclipseLink Wiki作为参考http://wiki.eclipse.org/Using_Basic_Query_API_(ELUG )。
The code is: 代码是:
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("p_environment.startSession");
List<String[]> args = new ArrayList<String[]>();
args.add(new String[] { "user", "ae01403" });
args.add(new String[] { "application", "app_code" });
args.add(new String[] { "locale", "it_IT" });
for (String[] pair : args) {
call.addNamedArgumentValue(pair[0], pair[1]);
}
DataReadQuery query = new DataReadQuery(call);
for (String[] pair : args) {
query.addArgument(pair[0]);
}
Based on database documentation, as I have no access to the database itself, the procedure takes 3 VARCHAR IN parameters of the specified name. 根据数据库文档,由于我无法访问数据库本身,因此该过程将使用3个具有指定名称的VARCHAR IN参数。 I then call the executeQuery method on the active session, but receive the "Wrong type or number of arguments" error. 然后,我在活动会话上调用executeQuery方法,但收到“错误的类型或参数数量”错误。 What am I doing wrong? 我究竟做错了什么? Any help is appreciated. 任何帮助表示赞赏。
EDIT: The stored procedure signature, as per documentation, is: 编辑:根据文档,存储过程签名为:
p_environment.startSession(as_user IN VARCHAR2,
as_application IN VARCHAR2,
as_locale IN VARCHAR2);
Many thanks! 非常感谢!
In your code, call.addNamedArgumentValue(pair[0], pair[1]);
在您的代码中, call.addNamedArgumentValue(pair[0], pair[1]);
sounds strange. 听起来很奇怪。
Don't you need to do this instead ? 您是否不需要这样做?
call.addNamedArgument(procedureParameterName, argumentFieldName, argumentType);
It enables the mapping between your stored procedure parameters and the args you want to use. 它启用了存储过程参数与要使用的args之间的映射。
For example, for you, it gives : 例如,对于您来说,它给出了:
call.addNamedArgument(procedureUserParameterName, "user", String.class);
call.addNamedArgument(procedureUserParameterName, "application", String.class);
call.addNamedArgument(procedureUserParameterName, "locale", String.class);
You keep this : 你保持这个:
DataReadQuery query = new DataReadQuery(call);
for (String[] pair : args) {
query.addArgument(pair[0]);
}
Then to call your Stored Procedure : 然后调用您的存储过程:
Session session = jpaEntityManager.getActiveSession();
List args = new ArrayList();
args.add(“ae01403”);
args.add(“app_code”);
args.add(“it_IT”);
List results = (List) session.executeQuery(query, args);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.