List of usage examples for org.hibernate Session delete
void delete(String entityName, Object object);
From source file:Beans.ListaProfesoresBeans.java
public void delete(String pege_id) throws IOException { Disponibilidad d = new Disponibilidad(); d = cod_dispoProfe(pege_id);//from w w w. ja v a 2s . co m ArrayList n = null; n = BuscarDispoAsesoria(d); System.out.println("Entroo delete pege " + pege_id + " dispo " + d.getCodDis()); if (n.size() > 0) { System.out.println("entro opcion 1"); Session session = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction t = session.beginTransaction(); try { d.setEstado("I"); session.update("Disponibilidad", d); t.commit(); } catch (Exception ex) { System.out.println("Error " + ex.toString()); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR", "")); } } else if (n.size() == 0) { System.out.println("entro opcion 2"); try { BorrarDispo(d); System.out.println("-- 1"); borrarDias(d); System.out.println("-- 2"); Session session = HibernateUtil.getSessionFactory().openSession(); Transaction t = session.beginTransaction(); System.out.println("-- 3"); session.delete("Disponibilidad", d); System.out.println("-- 4"); t.commit(); } catch (Exception ex) { System.out.println("Error hiber" + ex.toString()); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR", "")); } } FacesContext.getCurrentInstance().getExternalContext().redirect("Lista_Profesor.xhtml"); }
From source file:Beans.ListaProfesoresBeans.java
public boolean borrarDias(Disponibilidad d) { boolean r = false; Session session = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction t = session.beginTransaction(); ArrayList<Dia> dias = new ArrayList(); try {/*from w w w . ja v a2s . co m*/ dias = (ArrayList) session.createQuery( "select DI from Dia DI INNER JOIN " + " DI.disponibilidad D where D.codDis=" + d.getCodDis()) .list(); Dia temp = null; for (int i = 0; i < dias.size(); i++) { temp = (Dia) dias.get(i); session.delete("Dia", temp); } t.commit(); r = true; System.out.println("Borro dias " + r); } catch (Exception ex) { r = false; System.err.println("error Borrar Dias" + ex.toString()); } return r; }
From source file:Beans.ListaProfesoresBeans.java
public boolean BorrarDispo(Disponibilidad d) { boolean r = false; Session session = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction t = session.beginTransaction(); DispoUsuario dis = new DispoUsuario(); try {/*from ww w . jav a2 s.c o m*/ dis = (DispoUsuario) session.createQuery("select DI from DispoUsuario DI INNER JOIN " + " DI.disponibilidad D where D.codDis=" + d.getCodDis()).uniqueResult(); session.delete("DispoUsuario", dis); t.commit(); r = true; // session.getSessionFactory().close(); System.out.println("borro dispo " + r); } catch (Exception ex) { r = false; System.out.println("Error Borrar Dispo" + ex.toString()); } return r; }