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:com.asociate.dao.DirectorioDAO.java

/**
 *
 * @param idPersona/*from   ww  w . j  av a2  s  . com*/
 * @return
 */
public boolean hasDirectorioPersona(Long idPersona) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    Directorio dir = null;
    try {
        Query qu = sesion.createQuery(
                "Select D from Directorio D where D.idDirectorio = (Select A.idDirectorio from Asociacion A where A.idAsociacion in( Select SO from Socio SO where SO.idPersona = :idPer))");
        qu.setParameter("idPer", idPersona);
        qu.setMaxResults(1).getFirstResult();

    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
    return dir != null;
}

From source file:com.asociate.dao.DirectorioDAO.java

/**
 *
 * @param dir/*from w  w  w.j  av  a 2  s  . c  o  m*/
 */
public void guardar(Directorio dir) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();

    try {
        sesion.save(dir);

    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
}

From source file:com.asociate.dao.EventoAsistentesDAO.java

/**
 *
 * @param idEvento// www  .j a v a2s  . c  o  m
 * @return
 */
public List<Persona> getListaEvento(Long idEvento) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    List<Persona> salida = new ArrayList();
    try {
        Query qu = sesion.createSQLQuery(
                "Select P.* from PERSONA P join EVENTO_ASISTENTES E on E.ID_PERSONA = P.ID_PERSONA WHERE E.ID_EVENTO = :idE AND E.ESTADO = 'A' ");
        qu.setParameter("idE", idEvento);
        salida = qu.list();

    } catch (JDBCException c) {
        c.printStackTrace();

    } catch (Exception e) {
        e.printStackTrace();

    } finally {
        sesion.flush();
        sesion.close();
    }

    return salida;
}

From source file:com.asociate.dao.EventoAsistentesDAO.java

/**
 *
 * @param lista/*  w  w w .  ja  v  a2s . c om*/
 */
public void guardarAsistente(List<EventoAsistentes> lista) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();

    try {

        for (int i = 0; i < lista.size(); i++) {
            sesion.save(lista.get(i));
        }

    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
}

From source file:com.asociate.dao.EventoDAO.java

/**
 *
 * @param nuevo//from w  w w  . j a v a  2 s.  c o m
 * @return
 */
public Long guardarNuevoEvento(Evento nuevo) {
    Long error = 0L;

    Session sesion = HibernateUtil.getSessionFactory().openSession();
    try {

        error = (Long) sesion.save(nuevo);

    } catch (JDBCException c) {
        c.printStackTrace();
        error = -1L;

    } catch (Exception e) {
        e.printStackTrace();
        error = -1L;

    } finally {
        sesion.flush();
        sesion.close();

    }
    return error;
}

From source file:com.asociate.dao.EventoDAO.java

/**
 *
 * @param idEvento//from   www . j  ava 2  s .  c o  m
 * @return
 */
public Evento getEvento(Long idEvento) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    Evento salida = null;
    try {

        salida = (Evento) sesion.get(Evento.class, idEvento);

    } catch (JDBCException c) {
        c.printStackTrace();

    } catch (Exception e) {
        e.printStackTrace();

    } finally {
        sesion.flush();
        sesion.close();

    }

    return salida;
}

From source file:com.asociate.dao.EventoDAO.java

/**
 *
 * @param idPersona/*ww  w .j  ava 2s. co m*/
 * @return
 */
public List<Evento> getListaEvento(Long idPersona) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    List<Evento> salida = new ArrayList();
    try {
        Query qu = sesion.createQuery(
                "Select E from Evento E join fetch E.eventoAsistentesCollection EA where EA.idPersona = :id order by E.fhinicio desc");
        qu.setParameter("id", idPersona);
        salida = qu.list();
    } catch (JDBCException c) {
        c.printStackTrace();

    } catch (Exception e) {
        e.printStackTrace();

    } finally {
        sesion.flush();
        sesion.close();

    }

    return salida;
}

From source file:com.asociate.dao.EventoDAO.java

/**
 *
 * @param idUsuario/*from  ww  w.  j  a  va2 s . c o  m*/
 * @return
 */
public List<Evento> getListaEventoPropio(Long idUsuario) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    List<Evento> salida = new ArrayList();
    try {
        Query qu = sesion.createQuery(
                "Select E from Evento E where E.idCreador.idUsuario = :id order by E.fhinicio asc");
        qu.setParameter("id", idUsuario);
        salida = qu.list();
    } catch (JDBCException c) {
        c.printStackTrace();

    } catch (Exception e) {
        e.printStackTrace();

    } finally {
        sesion.flush();
        sesion.close();

    }

    return salida;
}

From source file:com.asociate.dao.MensajeriaDAO.java

/**
 *
 * @param idUsuario/*from w  ww.j av  a 2s.  c o m*/
 * @return
 */
public List<Mensajeria> getMensajesPendientes(Long idUsuario) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    List<Mensajeria> lista = new ArrayList();
    try {
        Query qu = sesion.createQuery(
                "Select M from Mensajeria M join fetch M.idOrigen  where M.idDestino.idUsuario=:id and M.leido='N' order by M.fhenvio desc")
                .setParameter("id", idUsuario);
        lista = qu.list();
    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
    return lista;
}

From source file:com.asociate.dao.MensajeriaDAO.java

/**
 *
 * @param idUsuario/*from   w ww  .j  a v  a 2 s.  c o m*/
 * @return
 */
public List<Mensajeria> getHistorico(Long idUsuario) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    List<Mensajeria> lista = new ArrayList();
    try {
        Query qu = sesion.createQuery(
                "Select M from Mensajeria M join fetch M.idDestino join fetch M.idOrigen where (M.idDestino.idUsuario=:id or M.idOrigen.idUsuario=:id) and M.leido=1 order by M.fhenvio desc")
                .setParameter("id", idUsuario);
        lista = qu.list();
    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
    return lista;
}