public List<SweCataDetret> listar(Integer idComponente, Integer idDetRet) { Session sessions = HibernateUtil.getSessionFactory().getCurrentSession(); try { sessions.beginTransaction(); Query q = sessions.createQuery(HQL_LISTAR); q.setParameter("idCatalogo", idComponente); q.setParameter("idDetRet", idDetRet); List<SweCataDetret> lista = q.list(); for (int i = 0; i < lista.size(); i++) { Hibernate.initialize(lista.get(i).getSweCata()); Hibernate.initialize(lista.get(i).getSweTipoDetret()); } return lista; } catch (HibernateException e) { return null; } finally { if (sessions.isOpen()) { sessions.close(); } } }
public Object agregar(List<SweCataDetret> catalogos) { Session sessions = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction transactions = null; try { transactions = sessions.beginTransaction(); for (int i = 0; i < catalogos.size(); i++) { sessions.saveOrUpdate(catalogos.get(i)); } sessions.flush(); sessions.clear(); transactions.commit(); return true; } catch (HibernateException e) { System.out.println(e.getMessage()); if (transactions != null) { transactions.rollback(); } if (sessions.isOpen()) { sessions.close(); } return e; } }