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.balero.models.TestDAO.java

License:Open Source License

@Transactional
public void delete(int id) {
    Session session = sessionFactory.openSession();
    Test test = new Test();
    Double n = Math.random();
    test.setId(id);//ww w  .  j  a  v a2 s  .co  m
    session.delete(test);
    session.flush();
    session.close();
}

From source file:com.balero.models.TestDAO.java

License:Open Source License

@Transactional
public void make() {
    Session session = sessionFactory.getCurrentSession();
    Test test = new Test();
    test.setId(1);//from   w  w w  .j av  a2 s  .c  o m
    test.setName("Anibal Gomez");
    test.setEmail("anibalgomez@balerocms.com");
    session.save(test);
    session.flush();
}

From source file:com.balero.models.UsersDAO.java

License:Open Source License

@Transactional
public void administratorCredentials(String password) {
    Session session = sessionFactory.getCurrentSession();
    Users users = new Users();
    users.setId(1); // Admin credentials id = 1
    users.setUsername("admin");
    users.setPassword(password);//  ww  w. ja  v  a 2  s. c  o  m
    users.setAuth("god");
    session.update(users);
    session.flush();
}

From source file:com.balero.models.UsersDAO.java

License:Open Source License

@Transactional
public void register(String username, String password, String name, String lastname, String email) {
    Session session = sessionFactory.getCurrentSession();
    Users users = new Users();
    users.setUsername(username);// w  w w  . j av a2  s  . c  o m
    users.setPassword(password);
    users.setName(name);
    users.setLastname(lastname);
    users.setEmail(email);
    users.setAuth("user");
    session.save(users);
    session.flush();
}

From source file:com.balero.models.UsersDAO.java

License:Open Source License

@Transactional
public void make() {
    Session session = sessionFactory.getCurrentSession();
    Users users = new Users();
    users.setId(1);/*from  w  w w.  ja  v a2 s.co  m*/
    users.setUsername("admin");
    users.setPassword("admin");
    users.setAuth("god");
    session.save(users);
    session.flush();
}

From source file:com.bandstand.web.BandsController.java

License:Apache License

@Move
public void move(Band band, BandsController newParent, String newName) {
    log.info("MOVE: band=" + band.getName() + " - to name=" + newName);
    Session session = SessionManager.session();
    Transaction tx = session.beginTransaction();
    band.setName(newName);//  ww  w.  ja  va 2 s . c  om
    session.save(band);
    session.flush();
    tx.commit();
    log.info("Saved band: " + band.getId());
}

From source file:com.baomidou.hibernateplus.dao.impl.DaoImpl.java

License:Open Source License

@Override
public boolean insertBatch(List<P> list, int size) {
    Assert.notEmpty(list);//from w  ww  .ja  v a 2 s  . c om
    try {
        Session session = HibernateUtils.getSession(masterSession(), isCurrent());
        for (int i = 0; i < list.size(); i++) {
            session.save(list.get(i));
            if (i % size == 0) {
                session.flush();
                session.clear();
            }
        }
    } catch (Exception e) {
        logger.warn("Warn: Unexpected exception.  Cause:" + e);
        return false;
    }
    return true;
}

From source file:com.baomidou.hibernateplus.dao.impl.DaoImpl.java

License:Open Source License

@Override
public boolean updateBatch(List<P> list, int size) {
    Assert.notEmpty(list);//from  w  w w . j  a v  a 2 s  .  c o m
    try {
        Session session = HibernateUtils.getSession(masterSession(), isCurrent());
        for (int i = 0; i < list.size(); i++) {
            session.merge(list.get(i));
            if (i % size == 0) {
                session.flush();
                session.clear();
            }
        }
    } catch (Exception e) {
        logger.warn("Warn: Unexpected exception.  Cause:" + e);
        return false;
    }
    return true;

}

From source file:com.baomidou.hibernateplus.dao.impl.DaoImpl.java

License:Open Source License

@Override
public boolean saveOrUpdateBatch(List<P> list, int size) {
    Assert.notEmpty(list);/* w  ww . j  a va2 s.  co  m*/
    try {
        Session session = HibernateUtils.getSession(masterSession(), isCurrent());
        for (int i = 0; i < list.size(); i++) {
            session.saveOrUpdate(list.get(i));
            if (i % size == 0) {
                session.flush();
                session.clear();
            }
        }
    } catch (Exception e) {
        logger.warn("Warn: Unexpected exception.  Cause:" + e);
        return false;
    }
    return true;

}

From source file:com.booleanworks.kryptopterus.application.MainHibernateUtil.java

License:Apache License

public Object saveOrUpdate(Object object, Session session) {
    System.out.println("com.booleanworks.kryptopterus.application.MainHibernateUtil.saveOrUpdate()");
    System.out.println("session  => " + session.hashCode());

    Object result = null;//from   w w w .  j a v a 2 s . com

    if (session == null || !session.isConnected() || !session.isOpen()) {
        session = this.getResidentSession();
    }

    if (session.isJoinedToTransaction()) {

        session.saveOrUpdate(object);
        if (!(session.getTransaction().getStatus() == TransactionStatus.MARKED_ROLLBACK)) {
            session.flush();
        }
        result = session.get(object.getClass(), session.getIdentifier(object));

    } else {
        Transaction transaction = this.beginTransaction(session, false);

        session.saveOrUpdate(object);
        if (!transaction.getRollbackOnly() && session.getFlushMode() != FlushModeType.AUTO) {
            session.flush();
        }
        result = session.get(object.getClass(), session.getIdentifier(object));

        this.commitTransaction(session, transaction);
    }

    return result;
}