使用Hibernate JPA 2.1调用Oracle存储过程,使用IN参数列表并输出Cursor

时间:2018-05-28 10:39:03

标签: oracle hibernate spring-boot stored-procedures spring-data-jpa

我正在尝试使用参数中的一组id调用存储过程,并期望返回一组Object结果。

我正在使用spring-boot-starter-data-jpa和ORacle DB 12c以及相应的JDBC驱动程序。

Oracle PL SQL:

PackageImports

然后在java方面:

create or replace type input_customer_ids is table of VARCHAR2(100);

create or replace procedure stored_p
    (customer_ids IN input_customer_ids,prc OUT sys_refcursor )as
       begin
       open
       prc for SELECT * FROM MY_TABLE 
       where customer_id IN (select * from table(customer_ids));
end;

我得到了:调用'STORED_P'

时参数的数量或类型错误
@PersistenceContext
    private EntityManager em;
.
.
public List<ClientAlertEntity> getAllClientAlertsList(List<String> customerIds) {
        StoredProcedureQuery findAllproc =
                em.createStoredProcedureQuery("STORED_P",ClientAlertEntity.class);
        findAllproc.registerStoredProcedureParameter("customer_ids", ArrayList.class, ParameterMode.IN);
        findAllproc.registerStoredProcedureParameter("prc", void.class, ParameterMode.REF_CURSOR);
        findAllproc.setParameter("customer_ids", customerIds);
        findAllproc.execute();
        @SuppressWarnings("unchecked")
        List<ClientAlertEntity> results = (List<ClientAlertEntity>)findAllproc.getResultList();
        return results;
    }

0 个答案:

没有答案