List of usage examples for org.hibernate Session delete
void delete(Object object);
From source file:caipsfa.app.modelo.GestionProveedores.java
public boolean deleteProvider(int id) { boolean estado = false; try {/*w w w . j a v a 2 s . c om*/ SessionFactory sesFact = HibernateUtil.getSessionFactory(); Session ses = sesFact.openSession(); Transaction trans = ses.beginTransaction(); Proveedores providers = (Proveedores) ses.get(Proveedores.class, id); ses.delete(providers); trans.commit(); ses.close(); estado = true; return estado; } catch (Exception e) { System.out.println(e); return estado; } }
From source file:caipsfa.app.modelo.GestionUnidades.java
public boolean deleteUnit(int id) { boolean estado = false; try {/* w ww .jav a 2s. com*/ SessionFactory sesFact = HibernateUtil.getSessionFactory(); Session ses = sesFact.openSession(); Transaction trans = ses.beginTransaction(); Unidades unit = (Unidades) ses.get(Unidades.class, id); ses.delete(unit); trans.commit(); ses.close(); estado = true; return estado; } catch (Exception e) { System.out.println(e); return estado; } }
From source file:caipsfa.app.modelo.GestionUsuarios.java
public boolean deleteUser(int id) { boolean estado = false; try {/* w w w. ja va 2 s . com*/ SessionFactory sesFact = HibernateUtil.getSessionFactory(); Session ses = sesFact.openSession(); Transaction trans = ses.beginTransaction(); Usuarios user = (Usuarios) ses.get(Usuarios.class, id); ses.delete(user); trans.commit(); ses.close(); estado = true; return estado; } catch (Exception e) { System.out.println(e); return estado; } }
From source file:Catalogo.editaCatalogo.java
private boolean eliminar(String idCatalogo) { Session session = HibernateUtil.getSessionFactory().openSession(); try {//from w w w .j ava 2 s. c o m session.beginTransaction(); actor = (Catalogo) session.get(Catalogo.class, Integer.parseInt(idCatalogo)); if (actor.getPartidas().isEmpty() == false) { session.getTransaction().rollback(); JOptionPane.showMessageDialog(null, "La descripcin esta en uso una partida no se puede eliminar!"); return false; } else { session.delete(actor); session.getTransaction().commit(); return true; } } catch (Exception e) { e.printStackTrace(); session.getTransaction().rollback(); return false; } finally { if (session.isOpen()) session.close(); } }
From source file:Category.categoryDelete.java
public static void categoryDeleteById(Integer catid) { Session session2; Category category;//from ww w . j a v a2 s . c om session2 = HibernateUtil.getSessionFactory().openSession(); session2.beginTransaction(); category = (Category) session2.load(Category.class, catid); session2.delete(category); //This makes the pending delete to be done session2.getTransaction().commit(); }
From source file:ch.algotrader.dao.AbstractDao.java
License:Open Source License
public void delete(final E entity) { Session currentSession = getCurrentSession(); currentSession.delete(entity); }
From source file:ch.icclab.cyclops.persistence.HibernateClient.java
License:Open Source License
/** * Remove object from database/*w ww . ja v a2s. co m*/ * @param obj object to be deleted */ public Boolean deleteObject(Object obj) { try { // get session Session session = obtainSession(); // now delete it session.delete(obj); // close session.flush(); session.close(); return true; } catch (Exception e) { return false; } }
From source file:ch.qos.logback.audit.persistent.Persistor.java
License:Open Source License
public static void delete(Object o) throws HibernateException { Session s = null; Transaction tx = null;/* w w w . j a v a2s .c om*/ try { s = openSession(); tx = s.beginTransaction(); s.delete(o); tx.commit(); } catch (HibernateException he) { if (tx != null) { tx.rollback(); } throw he; } finally { close(s, tx); } }
From source file:ch.tatool.app.service.impl.ModuleDAO.java
License:Open Source License
/** * Deletes a module/*from w ww . j a v a 2s .c o m*/ * * @param module the module to load */ public void deleteModule(final ModuleInfoImpl moduleInfo) { getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) { // PENDING: can't hibernate figure this out on its own? // First delete all trials List<?> trialIds = session .createQuery("select id from TrialImpl trial where trial.session.module.id = :id") .setParameter("id", moduleInfo.getId()).list(); for (Object o : trialIds) { TrialImpl trial = new TrialImpl(); session.load(trial, (Long) o); session.delete(trial); //session.createQuery("delete TrialImpl trial where trial.id = :id").setParameter("id", o).executeUpdate(); } session.flush(); // then delete the sessions List<?> sessionIds = session .createQuery("select id from ModuleSessionImpl session where session.module.id = :id") .setParameter("id", moduleInfo.getId()).list(); for (Object o : sessionIds) { ModuleSessionImpl s = new ModuleSessionImpl(); session.load(s, (Long) o); session.delete(s); } // finally delete the module // Does not work because for some reason the module properties are not deleted in cascade... /* Query query = session.createQuery("delete from ModuleImpl module where module-id = :moduleId"); query.setLong("moduleId", moduleInfo.getId()); query.executeUpdate(); */ // and finally the module itself ModuleImpl module = loadModule(moduleInfo); session.delete(module); return null; } }); }
From source file:chiron.maxscore.dao.impl.BaseDAOImpl.java
/** * /*from w ww . ja va2 s .c om*/ * * @param e */ @Override public void delete(E e) { Session session = sessionFactory.getCurrentSession(); session.delete(e); }