简体   繁体   中英

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

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:

create or replace 
type complex_list__t is table of simple_list__t

And the simple_list__t type is defined like this:

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. 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).

If it is not supported by JPA, Can I instead use a CLOB parameter instead of my array?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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