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:quizfun.model.dao.HibernateCourseDao.java

License:Open Source License

@Override
public Course updateCourse(Course course) {
    if (logger.isDebugEnabled()) {
        logger.debug("Updating Course: {}", course);
    }//from   ww w  .  j  a  v a 2 s.  c o  m
    Session session = getSession(false);
    try {
        return (Course) session.merge(course);
    } catch (HibernateException ex) {
        throw convertHibernateAccessException(ex);
    }
}

From source file:quizfun.model.dao.HibernateModuleDao.java

License:Open Source License

@Override
public Module updateModule(Module module) {
    if (logger.isDebugEnabled()) {
        logger.debug("Updating Module: {}", module);
    }/*  w  ww  . jav a 2s .c om*/
    Session session = getSession(false);
    try {
        return (Module) session.merge(module);
    } catch (HibernateException ex) {
        throw convertHibernateAccessException(ex);
    }
}

From source file:quizfun.model.dao.HibernateQuestionDao.java

License:Open Source License

@Override
public Question updateQuestion(Question question) {
    if (logger.isDebugEnabled()) {
        logger.info("Updating Question: " + question);
    }//from   w w  w .  ja  v  a  2 s  .  c  om
    Session session = getSession(false);
    try {
        return (Question) session.merge(question);

    } catch (HibernateException ex) {
        throw convertHibernateAccessException(ex);
    }
}

From source file:quizfun.model.dao.HibernateUserDao.java

License:Open Source License

@Override
public User updateUser(User user) {
    if (logger.isDebugEnabled()) {
        logger.debug("Updating User: {}", user);
    }// w ww  .ja v a  2  s  .  co m
    Session session = getSession(false);
    try {
        return (User) session.merge(user);
    } catch (HibernateException ex) {
        throw convertHibernateAccessException(ex);
    }
}

From source file:realestate.dao.impl.UserDaoImpl.java

License:Open Source License

/**
 * Cap nhat thong tin nguoi dung/*  w w w  .ja  va2s  .c  o  m*/
 * 
 * @param nguoiDung
 * @return true, if successful
 */
public boolean updateUser(User nd) {
    Session session = getSession();

    User nguoiDung = (User) session.get(User.class, nd.getUserId());
    if (nguoiDung != null) {
        try {
            nguoiDung.setActivationCode(null);
            nguoiDung.setStatus(ValidStatusEnum.SUCCESSFUL.getValue());
            nguoiDung.setActivationCodeTimes(nd.getActivationCodeTimes());
            // update nguoiDung
            session.merge(nguoiDung);
            return true;
        } catch (Exception e) {
            LOGGER.error("#updateUser: " + e);
        }
    }
    return false;
}

From source file:service.DatabaseService.java

@Override
@Transactional/*from  w  w w.  ja va  2 s . co  m*/
public void updateEntity(Object entity) {
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory();

    Session session = sessionFactory.openSession();
    session.setFlushMode(FlushMode.MANUAL);
    ManagedSessionContext.bind(session);
    Transaction tx = null;

    try {
        tx = session.beginTransaction();

        session.merge(entity);
        ManagedSessionContext.unbind(HibernateUtil.getSessionFactory());
        session.flush();
        tx.commit();
    } catch (RuntimeException e) {
        tx.rollback();
        throw e;
    } finally {
        session.close();
    }
}

From source file:services.ABM.java

License:Open Source License

public void update(T obj) {
    Session s = HibernateUtil.getSessionFactory().getCurrentSession();
    s.beginTransaction();/*from  w  w  w  . jav  a2s . co m*/
    //        User dbuser = (T) s.get(User.class, user.getId());
    s.merge(obj);
    s.getTransaction().commit();
    HibernateUtil.getSessionFactory().close();
}

From source file:Services.BabyService.java

public static Babyspullen BabyspullenUpdate(int id, Babyspullen baby) {
    Session s = HibernateUtil.getSessionFactory().openSession();
    baby.setId(id);/*  w w w  .  j  ava 2 s .c o m*/
    s.beginTransaction();
    s.merge(baby);
    s.getTransaction().commit();

    return baby;
}

From source file:Services.BoekService.java

public static Boeken BoekenUpdate(int id, Boeken boek) {
    Session s = HibernateUtil.getSessionFactory().openSession();
    boek.setId(id);//from   w  w  w .  j  ava2  s  .  c o m
    s.beginTransaction();
    s.merge(boek);
    s.getTransaction().commit();
    return boek;
}

From source file:services.estoque.EstoqueMovimentacaoService.java

public void insertPersonalizado(EstoqueMovimentacao estMov, Item i) throws services.ServiceException {
    Session s = getSession();
    synchronized (s) {
        Transaction t = s.beginTransaction();
        try {/*from ww w.j  a  v  a2s  .  c  om*/
            s.save(estMov);
            s.merge(i);
            t.commit();

        } catch (Exception e) {
            t.rollback();
            throw new services.ServiceException("Erro ao inserir " + classRef.getSimpleName(), e, logger);
        } finally {
            s.close();
        }
    }
}