Java Hibernate вызов функции оракула больше раз - PullRequest
0 голосов
/ 12 апреля 2019

Я использовал платформы Java Hibernate и EJB для вызова функции Oracle изнутри цикла for и использования вызываемого оператора close в блоке finally, после первого вызова и закрытия, второй вызов не может открыть соединение, и я получил ошибку: "org.hibernate.exception.GenericJDBCException: ошибка при выполнении работы"

private Object callDBFunctionWithParIndex(String functionName, List<Object> procParList, Integer returnParIndex) throws SQLException, Exception, BusinessException {
    Session hibernateSession = getEntityManager().unwrap(Session.class);
    Object returnMes = null;

    try {
        //That is important point,just pass object to ReturningWork<T> whatever you want to return from procedure, an also to execute method return type
        returnMes = hibernateSession.doReturningWork(new ReturningWork<Object>() {
            @Override
            public Object execute(Connection connection) throws SQLException {
                CallableStatement callStmnt = null;
                try {

                    Object innerReturn = null;
                    String inPar = adjustParameterString(procParList);
                    callStmnt = prepareCall(" { ? = call " + functionName + inPar + " } ", connection);
                    // Parameters can be numbered or named
                    if (procParList != null && procParList.size() > 0) {
                        for (int i = 0; i < procParList.size(); i++) {
                            FunctionCallParDTO funPar = (FunctionCallParDTO) procParList.get(i);
                            if (funPar.getParameterMode().equals(ParameterMode.IN)) {
                                callStmnt = addInParameter(callStmnt, i + 1, funPar.getParValue());
                            } else {
                                callStmnt = addOutParameter(callStmnt, i + 1, funPar.getParType());
                            }
                        }
                    }

                    excecute(callStmnt);

                    if (returnParIndex != null) {
                        innerReturn = getOutParameter(callStmnt, returnParIndex);
                    } else {
                        innerReturn = null;
                    }
                    return innerReturn;
                } catch (Exception ex) {
                    throw new SQLException("");
                } finally {
                    //DbUtils.closeQuietly(callStmnt);
                    //DbUtils.closeQuietly(connection);
                }
            }

        });
    } catch (HibernateException e) {
        throw e;
    }
    return returnMes;

}
...