Example usage for org.hibernate Session flush

List of usage examples for org.hibernate Session flush

Introduction

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

Prototype

void flush() throws HibernateException;

Source Link

Document

Force this session to flush.

Usage

From source file:br.com.aula.dao.EmpresaDAO.java

public void removerEmpresa(Empresa empresa) {
    Session session = factory.openSession();
    Transaction transaction = session.beginTransaction();
    session.delete(empresa);// ww  w  . ja  va 2s.  co  m
    session.flush();
    transaction.commit();
    session.close();
}

From source file:br.com.aula.dao.LoginDAO.java

public boolean existe(Usuario usuario) {
    Session session = factory.openSession();

    Query query = session.createQuery("from Usuario u where u.login = " + " :plogin and u.senha = :pSenha");
    query.setParameter("plogin", usuario.getUsuario());
    query.setParameter("pSenha", usuario.getSenha());
    boolean encontrado = !query.list().isEmpty();
    session.flush();
    session.close();//  w  w w  .j a v a 2  s. co  m
    return encontrado;
}

From source file:br.com.aula.dao.LoginDAO.java

public String buscaSenha(String senha) {
    Session session = factory.openSession();
    String senhaDB = (String) session.createQuery("from Usuario where senha = " + senha).list().iterator()
            .next();//from  w w  w  .j ava  2s . co m
    session.flush();
    session.close();
    return senhaDB;
}

From source file:br.com.aula.dao.LoginDAO.java

public String buscaUsuario(String senha) {
    Session session = factory.openSession();

    String usuario = (String) session.createQuery("from Usuario where senha = " + senha).list().iterator()
            .next();/*from   w  ww . ja v  a  2 s  . co m*/
    session.flush();
    session.close();
    return usuario;
}

From source file:br.com.foogames.database.dao.hibernateDAO.java

public static void insert(Object obj) {
    Session openSession = HibernateUtil.getSessionFactory().openSession();
    openSession.save(obj);//from   ww w.j  a  va2  s  . c  o m
    openSession.flush();
    openSession.close();
}

From source file:br.com.gaiatosfc.DAO.JogadoresDAOImp.java

@Override
public void salvar(Jogadores jogador) throws DAOException {
    Session session = null;
    try {/*from  w ww  . j av  a  2s. c om*/
        session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        session.save(jogador);
        t.commit();
        session.flush();
        session.clear();
    } catch (Exception e) {
        session.getTransaction().rollback();
        throw new DAOException(e);
    } finally {
        if (session != null) {
            session.close();
        }
    }

}

From source file:br.com.gaiatosfc.DAO.JogadoresDAOImp.java

@Override
public void deletar(Jogadores jogador) throws DAOException {
    Session session = null;
    try {//  www. ja v a 2s. c  om
        session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        session.flush();
        session.delete(jogador);

        t.commit();

        session.clear();
    } catch (Exception e) {
        session.getTransaction().rollback();
        throw new DAOException(e);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:br.com.jvmsoftware.daos.PubPosicaoDAO.java

public void inserirPosicao(PubPosicao pos) throws SQLException {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*  w w w .  jav a 2s  .c o m*/
    session.save(pos);
    session.flush();
    session.beginTransaction().commit();
    session.close();
}

From source file:br.com.prototipo.util.HibernateUtil.java

public static void closeSession() {
    Session session = (Session) sessionThread.get();
    sessionThread.set(null);/* w w  w . j  a  v a2s.  c o  m*/
    if (session != null && session.isOpen()) {
        session.flush();
        session.close();
    }
}

From source file:br.com.pucminas.debt.dao.impl.ValorMetricaDAOImpl.java

@Override
public void salvar(List<ValorMetrica> valoresMetrica) {

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = null;/*from ww  w.  j  a v a2 s .c  om*/
    try {
        session.beginTransaction();

        for (ValorMetrica val : valoresMetrica) {
            if (val.getValor() != null) {
                val.setId(0);
                session.save(val);
                session.flush();
                session.clear();
            }
        }
        session.getTransaction().commit();

    } catch (HibernateException e) {
        if (t != null) {
            t.rollback();
        }
    } finally {
        session.close();
    }
}