3

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

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

这也是实体上的命名查询定义:

@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);


}

当我getProc1在下面调用异常引发时:

Caused by: java.sql.SQLException: operation not allowed: Ordinal binding and Named binding cannot be combined!
    at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:10093)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:5693)
    at org.hibernate.result.internal.OutputsImpl.<init>(OutputsImpl.java:69)
    ... 72 more
4

2 回答 2

1

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

似乎您必须使用 StoredProcedureQuery 的显式创建EntityManager::createStoredProcedureQuery

于 2017-02-23T15:38:34.003 回答
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;
}
于 2018-05-10T11:51:27.047 回答