Example usage for org.hibernate Session delete

List of usage examples for org.hibernate Session delete

Introduction

In this page you can find the example usage for org.hibernate Session delete.

Prototype

void delete(Object object);

Source Link

Document

Remove a persistent instance from the datastore.

Usage

From source file:br.unisal.dao.PacienteDao.java

public void remove(Paciente p) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    try {/*from   w w  w .  j  av a2  s  .co  m*/
        tx.begin();
        session.delete(p);
        tx.commit();
    } catch (HibernateException e) {
        System.out.println("Exception PacienteDao.remove(): " + e.getMessage());
        tx.rollback();
    } finally {
        session.close();
    }
}

From source file:br.unisal.dao.ReuniaoDao.java

@Override
public void remove(Reuniao r) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    try {//  w  w  w.  j  av  a2  s  .com
        tx.begin();
        session.delete(r);
        tx.commit();
    } catch (HibernateException e) {
        System.out.println("Exception ReuniaoDao.remove(): " + e.getMessage());
        tx.rollback();
    } finally {
        session.close();
    }
}

From source file:br.unisal.dao.SalaDao.java

@Override
public void remove(Sala s) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    try {/*from w w  w .  ja v a2s .com*/
        tx.begin();
        session.delete(s);
        tx.commit();
    } catch (HibernateException e) {
        System.out.println("Exception SalaDao.remove(): " + e.getMessage());
        tx.rollback();
    } finally {
        session.close();
    }
}

From source file:br.unisal.dao.SensorDao.java

@Override
public void remove(Sensor s) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    try {//from w w  w.j  ava2  s .  co  m
        tx.begin();
        session.delete(s);
        tx.commit();
    } catch (HibernateException e) {
        System.out.println("Exception SensorDao.remove(): " + e.getMessage());
        tx.rollback();
    } finally {
        session.close();
    }
}

From source file:br.unisal.dao.UsuarioDao.java

@Override
public void remove(Usuario s) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    try {/*from   ww  w. j  ava 2 s . c  o m*/
        tx.begin();
        session.delete(s);
        tx.commit();
    } catch (HibernateException e) {
        System.out.println("Exception UsuarioDao.remove(): " + e.getMessage());
        tx.rollback();
    } finally {
        session.close();
    }
}

From source file:br.unisal.twitter.dao.TweetDao.java

public void remove(Tweet s) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    try {// www  .j a  v  a 2 s .co  m
        tx.begin();
        session.delete(s);
        tx.commit();
    } catch (HibernateException e) {
        System.out.println("Exception TweetDao.remove(): " + e.getMessage());
        tx.rollback();
    } finally {
        session.close();
    }
}

From source file:br.univel.common.Dao.java

public void delete(Model model) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*from   ww  w.j  ava 2 s  . co  m*/
    session.delete(model);
    session.getTransaction().commit();
    session.close();
    //    HibernateUtil.finalizar();
}

From source file:by.bsuir.akkerman.mobile.server.dao.DaoUniversal.java

public boolean delete(EntityHelper obj) {
    boolean isSuccessfully = false;
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
    Session session = sessionFactory.openSession();
    session.beginTransaction();/*from   ww  w  .ja  v  a 2s .  co m*/
    try {
        obj = (EntityHelper) session.get(obj.getClass(), obj.getId());
        session.delete(obj);
        if (!obj.getParent().isEmpty()) {
            Set<EntityHelper> set = new HashSet(obj.getParent());
            for (Iterator it = set.iterator(); it.hasNext();) {
                EntityHelper parent_obj = (EntityHelper) session.get(it.next().getClass(),
                        ((EntityHelper) it.next()).getId());
                parent_obj.getChild().add(obj);
                session.update(parent_obj);
            }
        }
        if (obj.getParent() != null) {
            Set<EntityHelper> set = new HashSet(obj.getParent());
            for (Iterator it = set.iterator(); it.hasNext();) {
                String[] lines = it.next().getClass().getName().split("_");
                EntityHelper parent_obj = (EntityHelper) session.get(lines[0],
                        ((EntityHelper) it.next()).getId());
                parent_obj.getChild().remove(obj);
                session.update(parent_obj);
            }

        }
        isSuccessfully = true;
    } catch (HibernateException ex) {
        System.out.println(ex.getMessage());
    } finally {
        session.getTransaction().commit();
        session.close();
    }
    return isSuccessfully;
}

From source file:by.telecom.subscriberapp.DAO.GenericDaoImpl.java

public void delete(T persistentObject) {
    Session session = null;
    try {//  ww w  .j  a  v  a2 s  .  c  o  m
        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.delete(persistentObject);
        session.getTransaction().commit();
    } catch (Exception e) {
        e.printStackTrace();

    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }
}

From source file:ca.mcgill.cs.swevo.qualyzer.model.Facade.java

License:Open Source License

/**
 * Try to delete a participant./*from ww w  .  j av  a  2s.c  o m*/
 * 
 * @param participant
 */
public void deleteParticipant(Participant participant) {
    Object project = null;
    HibernateDBManager manager = QualyzerActivator.getDefault().getHibernateDBManagers()
            .get(participant.getProject().getFolderName());
    Session session = null;
    Transaction t = null;

    try {
        session = manager.openSession();
        t = session.beginTransaction();

        /*
         * The following is ALL required in order to delete the object from the database. Don't ask me why, I don't
         * really understand it myself -JF.
         */
        project = session.get(Project.class, participant.getProject().getPersistenceId());
        Object part = session.get(Participant.class, participant.getPersistenceId());

        ((Project) project).getParticipants().remove(part);

        session.delete(part);
        session.saveOrUpdate(project);
        session.flush();
        t.commit();

        fListenerManager.notifyParticipantListeners(ChangeType.DELETE, new Participant[] { participant }, this);
    } catch (HibernateException e) {
        HibernateUtil.quietRollback(t);
        String key = "model.Facade.Participant.cannotDelete"; //$NON-NLS-1$
        String errorMessage = Messages.getString(key);
        fLogger.error(key, e);
        throw new QualyzerException(errorMessage, e);
    } finally {
        HibernateUtil.quietClose(session);
    }
}