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:com.atlanta.educati.daoImp.ModalidadingresoDaoImp.java

@Override
public int update(Modalidadingreso x) {
    Session sesion = sesionFactory.openSession();
    Transaction tx = sesion.beginTransaction();

    //Variable de respuesta
    int r = 0;//w w w.  jav a  2  s . c o  m

    try {
        sesion.clear();
        sesion.update(x);
        tx.commit();

        r++;
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
        tx.rollback();
    } finally {
        sesion.close();
    }

    return r;
}

From source file:com.atlanta.educati.daoImp.PermisoDaoImp.java

@Override
public int update(Permiso x) {
    Session sesion = sesionFactory.openSession();
    Transaction tx = sesion.beginTransaction();

    //Variable de respuesta
    int r = 0;//ww w  .j  a  v a  2  s .  c  om

    try {
        sesion.clear();
        sesion.update(x);
        tx.commit();

        r++;
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
        tx.rollback();
    } finally {
        sesion.close();
    }

    return r;
}

From source file:com.atlanta.educati.daoImp.PersonaDaoImp.java

@Override
public int update(Persona x) {
    Session sesion = sesionFactory.openSession();
    Transaction tx = sesion.beginTransaction();

    //Variable de respuesta
    int r = 0;//from   w  w w .ja  va2  s .c o m

    try {
        sesion.clear();
        sesion.update(x);
        tx.commit();

        r++;
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
        tx.rollback();
    } finally {
        sesion.close();
    }

    return r;
}

From source file:com.atlanta.educati.daoImp.RendimientoDaoImp.java

@Override
public int update(Rendimiento x) {
    Session sesion = sesionFactory.openSession();
    Transaction tx = sesion.beginTransaction();

    //Variable de respuesta
    int r = 0;/*w ww.  ja v a2 s. co m*/

    try {
        sesion.clear();
        sesion.update(x);
        tx.commit();

        r++;
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
        tx.rollback();
    } finally {
        sesion.close();
    }

    return r;
}

From source file:com.atlanta.educati.daoImp.TareaDaoImp.java

@Override
public int update(Tarea x) {
    Session sesion = sesionFactory.openSession();
    Transaction tx = sesion.beginTransaction();

    //Variable de respuesta
    int r = 0;/*w ww  . j a v a 2 s .  c o  m*/

    try {
        sesion.clear();
        sesion.update(x);
        tx.commit();

        r++;
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
        tx.rollback();
    } finally {
        sesion.close();
    }

    return r;
}

From source file:com.atlanta.educati.daoImp.TelefonoDaoImp.java

@Override
public int update(Telefono x) {
    Session sesion = sesionFactory.openSession();
    Transaction tx = sesion.beginTransaction();

    //Variable de respuesta
    int r = 0;//from ww w .j a v a 2 s.  c om

    try {
        sesion.clear();
        sesion.update(x);
        tx.commit();

        r++;
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
        tx.rollback();
    } finally {
        sesion.close();
    }

    return r;
}

From source file:com.atlanta.educati.daoImp.TutorDaoImp.java

@Override
public int update(Tutor x) {
    Session sesion = sesionFactory.openSession();
    Transaction tx = sesion.beginTransaction();

    //Variable de respuesta
    int r = 0;/*  ww w  .ja v  a 2  s . co m*/

    try {
        sesion.clear();
        sesion.update(x);
        tx.commit();

        r++;
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
        tx.rollback();
    } finally {
        sesion.close();
    }

    return r;
}

From source file:com.atlanta.educati.daoImp.UsuarioDaoImp.java

@Override
public int update(Usuario x) {
    Session sesion = sesionFactory.openSession();
    Transaction tx = sesion.beginTransaction();

    //Variable de respuesta
    int r = 0;/*from w ww  . j a v  a 2 s  .  co  m*/

    try {
        sesion.clear();
        sesion.update(x);
        tx.commit();

        r++;
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
        tx.rollback();
    } finally {
        sesion.close();
    }

    return r;
}

From source file:com.atlanta.educati.daoImp.VinculoDaoImp.java

@Override
public int update(Vinculo x) {
    Session sesion = sesionFactory.openSession();
    Transaction tx = sesion.beginTransaction();

    //Variable de respuesta
    int r = 0;/*from  w w w. jav a  2  s . c  om*/

    try {
        sesion.clear();
        sesion.update(x);
        tx.commit();

        r++;
    } catch (Exception e) {
        System.out.println("" + e.getMessage());
        tx.rollback();
    } finally {
        sesion.close();
    }

    return r;
}

From source file:com.autentia.intra.dao.hibernate.HibernateManagerBase.java

License:Open Source License

/**
 * Actualiza una objeto de negocio en base de datos
 *
 * @param obj el objeto de negocio a actualizar
 *//* www . j  av  a  2  s.co m*/
public void update(ITransferObject obj, Serializable pk) throws DataAccException {
    log.debug("update");
    Session session = null;
    try {

        session = HibernateUtil.currentSession();
        session.beginTransaction();
        // Cargamos el objeto antiguo
        //IZA         Object objOld = session.load(obj.getClass(), pk);
        log.debug("objeto con clave '" + pk + "' recuperado");
        // Copiamos las propiedades del objeto nuevo al antiguo
        //IZA         BeanUtils.copyProperties(objOld,obj);
        // Actualizamos
        //IZA         session.update(objOld);
        obj.setUpdatedById(SpringUtils.getPrincipal().getId());
        obj.setUpdateDate(new Date());
        //obj = obj.getClass().cast(session.merge(obj));
        try {
            session.update(obj);
        } catch (NonUniqueObjectException ex) {
            session.clear();
            session.update(obj);
        }
        Class cls = obj.getClass();
        try {
            if ((Boolean) cls.getField("historial").get(null)) {
                Historial entrada = new Historial();
                entrada.setFechaHora(new Date());
                entrada.setUsuario(SpringUtils.getPrincipal().getUser());
                entrada.setKlazz(cls);
                entrada.setIdObjeto(obj.getId());
                entrada.setTipoCambio(HistorialType.MODIFICADO);
                session.save(entrada);
            }
        } catch (NoSuchFieldException ex) {
            //pass
        }
        try {
            session.getTransaction().commit();

            log.debug("objeto con clave '" + pk + "' correctamente actualizado");
            if (this.cacheable)
                HibernateManagerBase.removeCacheFor(obj.getClass().getName());
        } catch (HibernateException ex) {
            session.getTransaction().rollback();
            session.clear();
        }
    } catch (Exception ex) {
        String msg = "Error actualizando el objeto '" + obj + "' con clave primaria '" + pk + "'";
        log.debug("error actualizando el objeto '" + pk + "': " + msg);
        throw new DataAccException(msg, ex);
    }
    /*finally{
        HibernateUtil.closeSession(session);
    }*/
}