我正在使用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 ...
这是工作。我得到对象列表数组。
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));
}