我使用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 ...
答案 0 :(得分:0)
这是工作。我得到了对象数组列表。
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));
}