不正确的序数绑定和命名绑定不能合并异常

时间:2016-04-18 11:15:45

标签: java jdbc spring-data sys-refcursor ref-cursor

我是一个Spring数据存储库,它调用使用命名查询定义的过程。存储过程有两个参数,第一个是ref_cursor,第二个是参数。这是sp签名:

create or replace procedure proc1(out_pos out sys_refcursor , pTrans_ID in Number) is  ............

这也是实体上的namedquery定义:

@javax.persistence.NamedStoredProcedureQuery(name = "getProc", procedureName = "proc1",
        parameters ={
                @StoredProcedureParameter(name = "out_pos",mode = ParameterMode.REF_CURSOR,type = void.class),
                @StoredProcedureParameter(name = "pTrans_ID",mode = ParameterMode.IN,type = Long.class)
        }
)

这是调用命名查询的存储库:

public interface TempReportRepository extends SwiftRepository<TempReportEntity,Long> {
    @Procedure(name = "getProc")
    public Object[] getProc1(@Param("pTrans_ID") Long inParam1);


}

当我在{1}}之外调用异常加注:

getProc1

2 个答案:

答案 0 :(得分:0)

如果您使用的是eclipselink 见https://bugs.eclipse.org/bugs/show_bug.cgi?id=440078

似乎您必须使用EntityManager::createStoredProcedureQuery

显式创建StoredProcedureQuery

答案 1 :(得分:0)

尝试顺序绑定

实体上的命名存储过程查询:

@NamedStoredProcedureQueries({
    @NamedStoredProcedureQuery(name = "getProc",
            procedureName = "proc1",
            resultClasses = TempReportEntity.class,
            parameters = {
                    @StoredProcedureParameter(mode = ParameterMode.IN,  type = Long.class),
                    @StoredProcedureParameter(mode = ParameterMode.REF_CURSOR,type = void.class)
            })})

调用功能

private final EntityManager entityManager;
public PurchaseOrderDetailsRepo( EntityManager entityManager) {
        this.entityManager = entityManager;
    }
public List<TempReportEntity> getProc1(Long pTrans_ID){
    StoredProcedureQuery query = entityManager.createNamedStoredProcedureQuery("getProc");
        query.setParameter(1,eid);
        query.execute();
    List<TempReportEntity> result = query.getResultList();
    return result;
}