Example usage for org.hibernate Session merge

List of usage examples for org.hibernate Session merge

Introduction

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

Prototype

Object merge(Object object);

Source Link

Document

Copy the state of the given object onto the persistent object with the same identifier.

Usage

From source file:com.smi.travel.datalayer.dao.impl.RoleMappingImpl.java

@Override
public int insertRolePrivilege(RoleMapping RoleMap, List<Function> functionList) {
    int result = 0;
    try {//from  w ww  .ja  v  a 2s. c o  m
        Session session = this.sessionFactory.openSession();
        transaction = session.beginTransaction();
        Query query = session.createQuery(DeleteMap);
        query.setString("roleid", RoleMap.getRole().getId());
        query.executeUpdate();
        for (Function f : functionList) {
            RoleMap.setFunction(f);
            session.merge(RoleMap);
        }
        transaction.commit();
        session.close();
        result = 1;
    } catch (Exception ex) {
        ex.printStackTrace();
        transaction.rollback();
        result = 0;
    }
    return result;
}

From source file:com.soen.hasslefree.dao.ObjectDao.java

public void addOrUpdateObject(Object object) {
    Session session = factory.openSession();
    Transaction tx = null;//from  w ww  .j a v  a 2  s. com
    try {
        tx = session.beginTransaction();
        // Adding Object
        session.merge(object);

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

}

From source file:com.soen.hasslefree.dao.ObjectDao.java

public void updateObject(Object object, long id, Class<T> ClassName)
        throws IllegalAccessException, InvocationTargetException {
    Session session = factory.openSession();
    Transaction tx = null;/*from  w ww  .  j a va  2 s  .  c o  m*/
    try {
        tx = session.beginTransaction();
        // Update Object

        this.t = (T) session.get(ClassName, id);
        BeanUtils.copyProperties(t, object);
        session.merge(t);
        tx.commit();
    } catch (HibernateException e) {
        if (tx != null) {
            tx.rollback();
        }
        e.printStackTrace();
    } finally {
        session.close();
    }
}

From source file:com.tala.enterprise.talabank.dao.account.impl.AccountDAOImpl.java

@Override
public boolean deposit(Account account, int amount) {
    boolean status = false;
    Session session = null;
    Transaction transaction = null;//from  w ww .  j a  v  a2  s  .c  o m

    try {
        SessionFactory sessionFactory = TalaBankHibernateUtil.getSessionFactory();
        session = sessionFactory.openSession();
        transaction = session.beginTransaction();

        com.tala.enterprise.talabank.model.db.Transaction entry = new com.tala.enterprise.talabank.model.db.Transaction(
                account, getTransactiontype(TalaBankConstants.getCASH_DEPOSIT_TYPE()), amount, new Date(),
                new Date());
        session.save(entry);

        account.setAccountBalance(account.getAccountBalance() + amount);
        session.merge(account);

        transaction.commit();
        session.close();

        status = true;
    } catch (HibernateException exception) {
        if (transaction != null) {
            transaction.rollback();
            if (session != null) {
                session.close();
            }
        }
        LOGGER.error(exception);
    }

    return status;
}

From source file:com.tala.enterprise.talabank.dao.account.impl.AccountDAOImpl.java

@Override
public boolean withdraw(Account account, int amount) {
    boolean status = false;
    Session session = null;
    Transaction transaction = null;//from   w  ww.j  a v a2  s .  c om

    try {
        SessionFactory sessionFactory = TalaBankHibernateUtil.getSessionFactory();
        session = sessionFactory.openSession();
        transaction = session.beginTransaction();

        com.tala.enterprise.talabank.model.db.Transaction entry = new com.tala.enterprise.talabank.model.db.Transaction(
                account, getTransactiontype(TalaBankConstants.getCASH_WITHDRAW_TYPE()), amount, new Date(),
                new Date());
        session.save(entry);

        account.setAccountBalance(account.getAccountBalance() - amount);
        session.merge(account);

        transaction.commit();
        session.close();

        status = true;
    } catch (HibernateException exception) {
        if (transaction != null) {
            transaction.rollback();
            if (session != null) {
                session.close();
            }
        }
        LOGGER.error(exception);
    }

    return status;
}

From source file:com.teamj.distribuidas.model.queries.OpcionesPerfilQueries.java

public static OpcionDePerfil insertarOpcionesXPerfil(OpcionDePerfil opcionesXPerfil) {
    Session session = HibernateUtilSeguridades.getSessionSeguridadFactory().getCurrentSession();
    OpcionDePerfil per = null;// w w w .j  a va2s . co  m
    try {
        per = (OpcionDePerfil) session.merge(opcionesXPerfil);
    } catch (HibernateException he) {
        System.err.println("Error OpcionDePerfil al insertar.");
        throw he;
    }
    return per;
}

From source file:com.teamj.distribuidas.model.queries.OpcionQueries.java

public static Opcion insertarOpcion(Opcion opcion) {
    Session session = HibernateUtilSeguridades.getSessionSeguridadFactory().getCurrentSession();
    Opcion per = null;// w ww . j a  v  a 2 s .  c  om
    try {
        per = (Opcion) session.merge(opcion);
    } catch (HibernateException he) {
        System.err.println("Error PersonaQueries al insertar.");
        throw he;
    }
    return per;
}

From source file:com.teamj.distribuidas.model.queries.PerfilQueries.java

public static Perfil insertarPerfil(Perfil perfil) {
    Session session = HibernateUtilSeguridades.getSessionSeguridadFactory().getCurrentSession();
    Perfil per = null;/*from   w w  w  .j  av  a 2  s.c  o m*/
    try {
        per = (Perfil) session.merge(perfil);
    } catch (HibernateException he) {
        System.err.println("Error PersonaQueries al insertar.");
        throw he;
    }
    return per;
}

From source file:com.teamj.distribuidas.model.queries.PersonalQueries.java

public static Persona insertarPersona(Persona persona) {
    Session session = HibernateUtilSeguridades.getSessionSeguridadFactory().getCurrentSession();
    Persona user = null;//from  ww w  . j a  v  a2s  . c om
    try {
        user = (Persona) session.merge(persona);
    } catch (HibernateException he) {
        System.err.println("Error PersonaQueries al insertar.");
        throw he;
    }
    return user;
}

From source file:com.teamj.distribuidas.model.queries.RolQueries.java

public static Rol insertarRolesOpcionPerfil(Rol rol) {
    Session session = HibernateUtilSeguridades.getSessionSeguridadFactory().getCurrentSession();
    Rol per = null;/*w  ww  .j a  v a2 s.co m*/
    try {
        per = (Rol) session.merge(rol);
    } catch (HibernateException he) {
        System.err.println("Error RolQueries al insertar.");
        throw he;
    }
    return per;
}