【问题标题】:Getting results from Ref Cursor Oracle using ProcedureCall hibernate to createStoredProcedureCall使用 ProcedureCall hibernate 从 Ref Cursor Oracle 获取结果以 createStoredProcedureCall
【发布时间】:2014-10-26 08:20:03
【问题描述】:

我正在使用 ProcedureCall 来创建存储过程:

    ProcedureCall procedure=getCurrentSession().createStoredProcedureCall("getContractServiceForContract");
    procedure.registerParameter(1, ResultSet.class , ParameterMode.REF_CURSOR);
    procedure.registerParameter(2, Integer.class, ParameterMode.IN);
    procedure.registerParameter(3, Integer.class, ParameterMode.IN);
    procedure.registerParameter(4, Integer.class, ParameterMode.IN);

    procedure.getParameterRegistration(2).bindValue(contractId);
    procedure.getParameterRegistration(3).bindValue(month);
    procedure.getParameterRegistration(4).bindValue(year);

在这之后我有:

    ResultSetOutput rso=(ResultSetOutput) procedure.getOutputs().getCurrent(); 

但是

getCurrent();

抛出异常:

 java.lang.UnsupportedOperationException: org.hibernate.dialect.Oracle10gDialect does not support resultsets via stored procedures

我尝试使用表达式:

 ResultSetOutput rso=(ResultSetOutput)procedure.getOutputs().getOutputParameterValue(1); 

但我又遇到了异常:

 org.hibernate.procedure.ParameterMisuseException: REF_CURSOR parameters should be accessed via results

任何想法如何使这项工作?我的程序开始于:

PROCEDURE getContractServiceForContract 
(
  pResultValue OUT PROCTYPES.ref_cursor,
  pContractID IN INT,
  pMonth IN INT,
  pYear IN INT,
  pIsLoadByAccountingPeriod IN INT default 0
) AS 
yearMin int;
yearMax int;
monthMin int;
monthMax int;
vContractIDs t_num_ids_tab;       --holds event id's
vContractServIDs t_num_ids_tab;       --holds event id's
BEGIN   ...      

【问题讨论】:

标签: java spring oracle hibernate stored-procedures


【解决方案1】:

这是工作。我得到对象数组列表。

StoredProcedureQuery query = em.createStoredProcedureQuery(GET_GOODS_PROCEDURE)
                .registerStoredProcedureParameter(1, GoodTest.class, ParameterMode.REF_CURSOR)
                .registerStoredProcedureParameter(2, String.class, ParameterMode.OUT)
                .registerStoredProcedureParameter(3, Integer.class, ParameterMode.OUT);

        query.execute();
        List<Object[]> goods = query.getResultList();

        for (Object[] good : goods) {
            System.out.println(Arrays.toString(good));
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-23
    • 2016-07-10
    • 2022-08-24
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多