Example usage for org.hibernate Session clear

List of usage examples for org.hibernate Session clear

Introduction

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

Prototype

void clear();

Source Link

Document

Completely clear the session.

Usage

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

@Transactional
public boolean atualizar(Calendario calendario) {
    Session session = sessionFactory.getCurrentSession();
    try {//from   ww  w  .  j a va2 s . c  om
        session.update(calendario);
        if (calendario.isAtivo() == true) {
            disableOthers(session, calendario);
        }
        return true;
    } catch (HibernateException e) {
        System.out.println(e.getMessage());
        session.clear();
        return false;
    }
}

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

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

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

private void disableOthers(Session session, Calendario calendario) {
    Criteria criteria = session.createCriteria(Calendario.class);
    List<Calendario> calendarioList = criteria.list();
    int counter = 0;
    for (Calendario c : calendarioList) {
        if (!Objects.equals(c.getId(), calendario.getId())) {
            c.setAtivo(false);/*from  w  w w .  java  2 s  .  c  om*/
            session.save(c);
        }
        if (++counter % 20 == 0) {
            session.flush();
            session.clear();
        }
    }
}

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

@Transactional
public boolean adicionar(Evento evento) {
    Session session = sessionFactory.getCurrentSession();
    try {/*from  w w w.j  av a  2 s  .  c om*/
        session.clear();
        session.save(evento);
        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 adicionar(List<Evento> eventos) {
    Session session = sessionFactory.getCurrentSession();
    int counter = 0;
    try {/*  w w w  .j a va 2  s.  c om*/
        session.clear();
        for (Evento evt : eventos) {
            session.save(evt);
            if (++counter % 20 == 0) {
                session.flush();
                session.clear();
            }
        }
        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 atualizar(Evento evento) {
    Session session = sessionFactory.getCurrentSession();
    try {//from   w  ww .java2  s .  c o m
        session.clear();
        session.update(evento);
        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 {/*w w  w  . jav  a  2  s  .c  om*/
        session.delete(evento);
        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(Calendario calendario) {
    Session session = sessionFactory.getCurrentSession();
    try {/*  w  w  w. j ava  2  s  . c om*/
        session.createQuery("delete from Evento e where e.calendario.id = :id")
                .setLong("id", calendario.getId()).executeUpdate();
        return true;
    } catch (HibernateException e) {
        System.out.println(e.getMessage());
        session.clear();
        return false;
    }
}

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

@Transactional
public boolean adicionar(Interessado interessado) {
    Session session = this.sessionFactory.getCurrentSession();
    try {/*  ww w  .j  a va 2 s .  c  om*/
        session.save(interessado);
        return true;
    } catch (HibernateException e) {
        System.out.println(e.getMessage());
        session.clear();
        return false;
    }
}

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

@Transactional
public boolean atualizar(Interessado interessado) {
    Session session = this.sessionFactory.getCurrentSession();
    try {/*from ww w. j  av a2 s  .c  o  m*/
        session.update(interessado);
        return true;
    } catch (HibernateException e) {
        System.out.println(e.getMessage());
        session.clear();
        return false;
    }
}