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.msf.commons.persistence.dao.AbstractEntityDaoBean.java

License:Open Source License

@Override
public void deleteAll(final Collection<T> entities) {
    if (!CollectionUtils.isEmptyOrNull(entities)) {
        final Session session = getCurrentSession();
        int i = 0;
        for (T entity : entities) {
            session.delete(entity);
            // flush a batch of inserts and release memory, every 100 rows:
            if (i % 100 == 0) {
                flush();//from w w w .j  av  a 2 s.  c o  m
            }
        }
    }
}

From source file:br.msf.commons.persistence.dao.AbstractEntityDaoBean.java

License:Open Source License

@Override
public T deleteById(final ID id) {
    ArgumentUtils.rejectIfNull(id);//from   www  . j  av a2  s  . c o m
    final Session session = getCurrentSession();
    final T entity = findById(id);
    session.evict(entity);
    if (entity != null) {
        session.delete(entity);
    }
    return entity;
}

From source file:br.sp.telesul.dao.FuncionarioDAOImpl.java

@Override
public void delete(Funcionario funcionario) {
    Session session = this.sessionFactory.openSession();
    try {//  ww w  . j av a2s.  c om
        tx = session.beginTransaction();
        session.delete(funcionario);
        tx.commit();
        logger.info("Funcionrio Deleted Sucessfully", funcionario.getNome());
    } catch (Exception e) {
        if (tx != null) {
            tx.rollback();
        }
        logger.error("Error in delete funcionrio" + " ", e);
        System.out.println("erro" + e);
    } finally {
        session.close();
    }
}

From source file:br.sp.unifae.cris.comp7.model.dao.DAOEntrada.java

public void excluir(Entrada entrada) {

    Session session = DAOHibernateUtil.getSession();

    try {/*from   w w w .  jav a 2s  . co  m*/

        session.beginTransaction(); // Abre-se uma transao
        session.delete(entrada); // Acumula a operao de excluso do objeto entrada no BD, na transao
        session.getTransaction().commit(); // Realiza definitivamente todas as operaes pendentes na transao
        JOptionPane.showMessageDialog(null, "Entrada excluda com sucesso");

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex);

    }
}

From source file:br.sp.unifae.cris.comp7.model.dao.DAOEntradaProduto.java

public void excluir(EntradaProduto entradaProduto) {

    Session session = DAOHibernateUtil.getSession();

    try {/*from  w  w w  . j  a  v  a 2  s  .  c om*/

        session.beginTransaction(); // Abre-se uma transao
        session.delete(entradaProduto); // Acumula a operao de excluso do objeto entrada no BD, na transao
        session.getTransaction().commit(); // Realiza definitivamente todas as operaes pendentes na transao

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex);

    }
}

From source file:br.sp.unifae.cris.comp7.model.dao.DAOProduto.java

public void excluir(Produto produto) {

    Session session = DAOHibernateUtil.getSession();

    try {/*from  ww w  .  j av  a  2s .  co  m*/

        session.beginTransaction(); // Abre-se uma transao
        session.delete(produto); // Acumula a operao de excluso do objeto produto no BD, na transao
        session.getTransaction().commit(); // Realiza definitivamente todas as operaes pendentes na transao
        JOptionPane.showMessageDialog(null, "Produto excludo com sucesso");

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex);

    }
}

From source file:br.uece.goes.model.ObjectDAO.java

public void delete(Object object) {
    Session s = openSession();
    s.beginTransaction();
    s.delete(object);
    s.getTransaction().commit();
    s.close();
}

From source file:br.uem.projetoExtensao.DAO.AreaAbrangenciaDAO.java

public boolean excluir(Session session, Long id_abrangencia) {
    boolean r = true;
    try {/*from   ww w.j a v a 2 s .  co m*/
        AreaAbrangencia sistema = (AreaAbrangencia) session.get(AreaAbrangencia.class, id_abrangencia);
        if (sistema.getCd_area() > 0) {
            //campos a serem alterados

            session.delete(sistema);
        }

    } catch (Exception e) {
        r = false;
    }
    return r;
}

From source file:br.ufg.calendario.dao.CalendarioDao.java

@Transactional
public boolean excluir(Calendario calendario) {
    Session session = this.sessionFactory.getCurrentSession();
    try {/*w w w. j  a  v  a2s .c o m*/
        session.delete(calendario);
        return true;
    } catch (HibernateException e) {
        System.out.println(e.getMessage());
        session.clear();
        return false;
    }
}

From source file:br.ufg.calendario.dao.EventoDao.java

@Transactional
public boolean excluir(Evento evento) {
    Session session = sessionFactory.getCurrentSession();
    try {//ww  w  .j  a v  a2  s .c om
        session.delete(evento);
        return true;
    } catch (HibernateException e) {
        System.out.println(e.getMessage());
        session.clear();
        return false;
    }
}