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.yize.broadcast.core.hibernate.SimpleHibernateDao.java

License:Apache License

/**
 * ??.//from  w  w w  . j  a v  a  2  s . com
 */
@Transactional
public void batchSave(final List<T> entities) {
    Assert.notNull(entities, "entity?");
    Session session = getSession();
    int count = 0;
    for (T entity : entities) {
        session.saveOrUpdate(entity);
        ++count;
        if (count % 50 == 0) {
            session.flush();
            session.clear();
        }
    }
}

From source file:com.zhu.service.CarService.java

public List<Car> getEmptyCar() {
    Session session = HibernateSessionFactory.getSession();
    session.clear();
    StringBuffer hql = new StringBuffer();
    hql.append("from Car where status = 0");
    Query query = session.createQuery(hql.toString());
    List<Car> car = query.list();
    session.close();//from   w ww  .  j av a2 s . co m
    return car;
}

From source file:com.zhu.service.CarService.java

public void updCar(Car car) {
    Session session = HibernateSessionFactory.getSession();
    session.clear();
    Transaction transaction = session.beginTransaction();
    session.merge(car);//from w w w.  j  a  v a2 s. c o  m
    session.flush();
    transaction.commit();
    session.close();
}

From source file:cz.zcu.pia.social.network.backend.services.dao.GenericDAO.java

/**
 * Closes session with transaction//from ww  w. j ava 2s. co m
 *
 * @param s session
 */
private void closeSessionWithTransaction(Session s) {
    s.flush();
    this.currentTransaction.commit();
    s.clear();
    s.close();

}

From source file:dao.BolsistaDAO.java

public static List<Bolsista> obterBolsistas() throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  w  w  w.ja  v  a 2s .c o  m*/
    session.clear();
    List<Bolsista> bolsistas = session.createCriteria(Bolsista.class).list();

    return bolsistas;
}

From source file:dao.BolsistaDAO.java

public static List<Bolsista> obterBolsistaPorNome(String nomeBolsista)
        throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/* www . j  a va  2s . c  om*/
    session.clear();
    List<Bolsista> bolsistas = session.createQuery("from bolsista where nome like '%' +nomeBolsista+'%'")
            .list();

    return bolsistas;
}

From source file:dao.BolsistaDAO.java

public static Bolsista obterBolsista(int matricula) throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//ww w .  j a v  a  2s.  c o  m
    session.clear();
    Bolsista bolsista = (Bolsista) session.load(Bolsista.class, matricula);

    return bolsista;

}

From source file:dao.BolsistaDAO.java

public static void gravar(Bolsista bolsista) throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction transaction = session.beginTransaction();
    session.clear();
    session.save(bolsista.getPessoas());
    session.save(bolsista);//from  w w w .  j a  va 2 s .  co  m
    transaction.commit();

}

From source file:dao.BolsistaDAO.java

public static void editar(Bolsista bolsista) throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction transaction = session.beginTransaction();
    session.clear();
    session.update(bolsista);//from  w w  w .  j a  v a  2s.  co  m
    session.update(bolsista.getPessoas());
    transaction.commit();

}

From source file:dao.BolsistaDAO.java

public static void excluir(Bolsista bolsista) throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction transaction = session.beginTransaction();
    session.clear();
    session.delete(bolsista);/*ww w .  j av a 2 s.c o  m*/
    session.delete(bolsista.getPessoas());
    transaction.commit();

}