Example usage for org.hibernate Session update

List of usage examples for org.hibernate Session update

Introduction

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

Prototype

void update(Object object);

Source Link

Document

Update the persistent instance with the identifier of the given detached instance.

Usage

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;/*www.ja 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.TutorDaoImp.java

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

    //Variable de respuesta
    int r = 0;//from w  ww .  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.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  .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.VinculoDaoImp.java

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

    //Variable de respuesta
    int r = 0;/*from   w  ww .  j a  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.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
 *///from w w w.j a  v  a2s .  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);
    }*/
}

From source file:com.avectis.transportcontrol.DAO.CardHibernateDAO.java

/**
* unpade Card using Hibernate/* w w w  .  j a  va 2 s .  c o  m*/
* 
* @param card Card - witch entity to update
*/
@Override
public void Update(Card card) {
    Session session = sessionFactory.getCurrentSession();
    session.update(card);
}

From source file:com.avectis.transportcontrol.DAO.CarHibernateDAO.java

/**
* unpade entity using Hibernate/*from w  ww . ja  v  a  2  s  .co m*/
* 
* @param car Car - witch entity to update
*/
@Override
public void update(Car car) {
    Session session = sessionFactory.getCurrentSession();
    session.update(car);
}

From source file:com.avectis.transportcontrol.DAO.QueueHibernateDAO.java

/**
 * unpade entity using Hibernate//w w w .  j a v  a  2s .c  om
 * 
 * @param queue Queue - witch entity to update
 */
@Override
public void update(Queue queue) {
    Session session = sessionFactory.getCurrentSession();
    session.update(queue);
}

From source file:com.avectis.transportcontrol.DAO.UserHibernateDAO.java

@Override
public void update(User user) {
    Session session = sessionFactory.getCurrentSession();
    session.update(user);
}

From source file:com.avectis.transportcontrol.DAO.UserHibernateDAO.java

@Override
public void update(UserRole userRole) {
    Session session = sessionFactory.getCurrentSession();
    session.update(userRole);
}