@SuppressWarnings("rawtypes") private void inicializarPropriedadesLazies(Collection colecao) { for (Iterator iter = colecao.iterator(); iter.hasNext(); ) { Object element = iter.next(); if (element instanceof ObjetoTransacao) { ObjetoTransacao objTrans = (ObjetoTransacao) element; objTrans.initializeLazy(); } } }
@SuppressWarnings("rawtypes") public void remover( int id, String pacoteNomeObjeto, OperacaoEfetuada operacaoEfetuada, Collection<UsuarioAcaoUsuarioHelper> acaoUsuarioHelper) throws ErroRepositorioException { Session session = HibernateUtil.getSession(); try { Iterator iterator = session .createQuery("from " + pacoteNomeObjeto + " where id = :id") .setInteger("id", id) .iterate(); if (!iterator.hasNext()) { throw new RemocaoRegistroNaoExistenteException(); } while (iterator.hasNext()) { Object obj = iterator.next(); if (obj instanceof ObjetoTransacao && operacaoEfetuada != null) { ObjetoTransacao objetoTransacao = (ObjetoTransacao) obj; objetoTransacao.setOperacaoEfetuada(operacaoEfetuada); Iterator it = acaoUsuarioHelper.iterator(); while (it.hasNext()) { UsuarioAcaoUsuarioHelper helper = (UsuarioAcaoUsuarioHelper) it.next(); objetoTransacao.adicionarUsuario(helper.getUsuario(), helper.getUsuarioAcao()); } } iterator.remove(); } session.flush(); } catch (JDBCException e) { throw new RemocaoInvalidaException(e); } catch (CallbackException e) { throw new ErroRepositorioException(e, e.getMessage()); } catch (HibernateException e) { throw new ErroRepositorioException(e, "Erro no Hibernate"); } finally { HibernateUtil.closeSession(session); } }