简体   繁体   English

如何使用JPA 2在存储过程中将复杂对象数组作为IN参数传递

[英]How to pass Array of complex objects as a IN parameter in a stored procedure using JPA 2

I am trying to call an Oracle stored procedure 我正在尝试调用Oracle存储过程

create or replace 
  procedure save_item (
                            item_arr__p in     complex_list__t,
                            status__p           out varchar2,
                            status_message__p   out varchar2) is
...
begin
...
end

And the complex_list__t type is defined like this: 而且complex_list__t类型的定义如下:

create or replace 
type complex_list__t is table of simple_list__t

And the simple_list__t type is defined like this: 并且simple_list__t类型的定义如下:

create or replace 
type simple_list__t  is table of varchar2(2000)

I want to call this procedure using JPA 2. I am not sure that JPA supports arrays as parameters. 我想使用JPA 2调用此过程。我不确定JPA是否支持将数组作为参数。 I would like to be able to do this: 我希望能够做到这一点:

StoredProcedureQuery query = em.createNamedStoredProcedureQuery("pkg_api_wd_item.save_item");
query.registerStoredProcedureParameter("item_arr__p", MyComplexObject[].class, ParameterMode.IN);
query.registerStoredProcedureParameter("status__p", String.class, ParameterMode.OUT);
query.registerStoredProcedureParameter("status_message__p", String.class, ParameterMode.OUT);

query.setParameter("item_arr__p", myobjects);
query.execute();

String status = (String) query.getOutputParameterValue("status__p");
String message = (String) query.getOutputParameterValue("status_message__p");

I really would like to use JPA as I want my application to be agnostic (no oracle dependencies). 我真的很想使用JPA,因为我希望我的应用程序是不可知的(没有oracle依赖项)。

If it is not supported by JPA, Can I instead use a CLOB parameter instead of my array? 如果JPA不支持它,那么我可以使用CLOB参数代替数组吗?

You might try passing a 您可以尝试通过

List<MyComplexObject> 

instead of an array of them. 而不是它们的数组。 If that doesn't work, you might try 如果这样不起作用,您可以尝试

List<List<String>>

instead of either. 而不是任何一个。

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

相关问题 如何使用 jTDS 将表值参数传递给存储过程? - How to pass a table-valued parameter to a stored procedure using jTDS? 是否可以将空参数传递给 Java JPA 2.1 中的存储过程? - Is it possible to pass a null parameter to a stored procedure in Java JPA 2.1? 我们可以将Java复杂对象(对象内部的对象)传递给存储过程吗? 怎么样? - Can we pass java complex objects(object inside object) to stored procedure? how? 如何将IN参数传递给mysql存储过程 - How to pass IN parameter to a mysql stored procedure 如何在存储过程中将架构名称作为参数传递 - How to pass schema name as parameter in stored procedure 使用jpa 2.0调用具有out参数的存储过程 - calling a stored procedure having out parameter using jpa 2.0 如何使用JPA将数组参数传递给Postgresql函数? - how to pass an array parameter using jpa to a postgresql function? 使用 OUT 参数调用存储过程 Spring Spring JPA 2.* - Calling stored procedure using OUT parameter with Spring Spring JPA 2.* Oracle 11g:使用简单的 jdbc 调用将数组作为输入参数传递给 oracle 存储过程 - Oracle 11g: Pass array as input parameter to an oracle stored procedure using simple jdbc call 使用简单的jdbc调用将数组作为输入参数传递给oracle存储过程 - Pass array as input parameter to an oracle stored procedure using simple jdbc call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM