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:dao.TipoCursoDAO.java

public static List<Tipocurso> obterTipoCursos() throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from   www.  ja va 2 s. co  m*/
    session.clear();
    List<Tipocurso> tipoCursos = session.createCriteria(Tipocurso.class).list();

    return tipoCursos;
}

From source file:dao.TipoCursoDAO.java

public static List<Tipocurso> obterTipoCursoPorNome(String nomeTipoCurso)
        throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from   ww w .  ja v  a2 s  . c om*/
    session.clear();
    List<Tipocurso> tipoCursos = session
            .createQuery("from tipoCurso where nome like '%' " + nomeTipoCurso + "'%'").list();

    return tipoCursos;
}

From source file:dao.TipoCursoDAO.java

public static Tipocurso obterTipoCurso(int codigoTipoCurso) throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from ww w .  j av  a  2  s  .  c o  m*/
    session.clear();
    Tipocurso tipoCurso = (Tipocurso) session.load(Tipocurso.class, codigoTipoCurso);

    return tipoCurso;

}

From source file:dao.TipoCursoDAO.java

public static void gravar(Tipocurso tipoCurso) throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction transaction = session.beginTransaction();
    session.clear();
    session.save(tipoCurso);//from   www  .j a  v  a2 s .c  o m
    transaction.commit();

}

From source file:dao.TipoCursoDAO.java

public static void editar(Tipocurso tipoCurso) throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction transaction = session.beginTransaction();
    session.clear();
    session.update(tipoCurso);/*from   w  w  w .j av  a 2 s.c om*/
    transaction.commit();

}

From source file:dao.TipoCursoDAO.java

public static void excluir(Tipocurso tipoCurso) throws SQLException, ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction transaction = session.beginTransaction();
    session.clear();
    session.delete(tipoCurso);/*from  w  ww . ja v a2  s. co m*/
    transaction.commit();

}

From source file:database.services.common.Batcher.java

public void batchUpdate(Session session) {
    if (number % BATCH_SIZE == 0 && number > 0) {
        session.flush();//from  w  ww .ja  v  a2s  .  c  o m
        session.clear();
    }
    number++;
}

From source file:de.codesourcery.eve.skills.util.DBConverter.java

License:Apache License

protected void export(Class<?> entity) {

    System.out.println("\n============\nExporting " + entity.getName() + "\n============");

    // load data//w  w w  .  j a va2s  . c om
    System.out.print("Opening MySQL session ...");
    final Session mysqlSession = mysql.openSession();
    System.out.print("created.");

    //      mysqlSession.setFlushMode( FlushMode.MANUAL );

    Transaction mysqlTransaction = mysqlSession.beginTransaction();

    final Criteria criteria = mysqlSession.createCriteria(entity);

    // replicate data
    System.out.print("Opening HSQL session ...");
    final Session hsqlSession = hsql.openSession();
    System.out.println("created.");
    //      mysqlSession.setFlushMode( FlushMode.MANUAL );

    final Transaction hsqlTransaction = hsqlSession.beginTransaction();

    final ScrollableResults data = criteria.scroll();
    int count = 0;
    int dotCount = 0;
    try {
        while (data.next()) {
            Object loaded = data.get(0);
            //            if ( entity == MarketGroup.class ) {
            //               MarketGroup group = (MarketGroup) loaded;
            //               System.out.println( group.getId() +" -> "+group.getParent() );
            //            }
            hsqlSession.replicate(loaded, ReplicationMode.IGNORE);
            if ((++count % 1000) == 0) { // make sure to adjust <prop key="hibernate.jdbc.batch_size">1000</prop> in config !!
                hsqlSession.flush();
                hsqlSession.clear();
                mysqlSession.flush();
                mysqlSession.clear();
                System.out.print(".");
                dotCount++;
                if (dotCount == 60) {
                    System.out.println();
                    dotCount = 0;
                }
            }
        }
    } finally {
        data.close();
        System.out.println("\nExported " + count + " entries");
    }

    if (mysqlTransaction.isActive()) {
        mysqlTransaction.commit();
    }

    if (hsqlTransaction.isActive()) {
        hsqlTransaction.commit();
    }

    hsqlSession.flush();
    mysqlSession.flush();

    mysqlSession.close();
    hsqlSession.close();
}

From source file:de.fau.osr.core.db.HibernateUtil.java

License:Open Source License

public void closeSession(Session session) {
    session.clear();
    session.close();
}

From source file:de.fhdo.gui.admin.modules.terminology.Associations.java

License:Apache License

private void initList() {
    logger.debug("initList()");
    // Header//  ww w  .  ja  v  a2s .c  om
    List<GenericListHeaderType> header = new LinkedList<GenericListHeaderType>();
    header.add(new GenericListHeaderType("ID", 90, "", true, "String", true, true, false, false));
    header.add(new GenericListHeaderType("Name vorwrts", 250, "", true, "String", true, true, false, false));
    header.add(
            new GenericListHeaderType("Name rckwrts", 250, "", true, "String", true, true, false, false));
    header.add(new GenericListHeaderType("Codesystem", 350, "", true, "String", true, true, false, false));

    //CacheManager.getInstance().clearAll();
    //clearHibernateCache();
    // Daten laden
    //SessionFactory sf = HibernateUtil.getSessionFactory();
    SessionFactory sf = HibernateUtil.getNewSessionFactory();

    //sf.evictQueries();
    //sf.getCurrentSession().clear();
    /*Cache cache = sf.getCache();
            
    cache.evictEntityRegions();
    cache.evictCollectionRegions();
    cache.evictDefaultQueryRegion();
    cache.evictQueryRegions();
    //cache.evictNaturalIdRegions();
    //cache.evictAllRegions();
            
    cache.evictAllRegions(); // Evict data from all query regions.*/

    Session hb_session = sf.openSession();

    //hb_session.getTransaction().begin();

    List<GenericListRowType> dataList = new LinkedList<GenericListRowType>();
    try {
        String hql = "select distinct at from AssociationType at"
                + " join fetch at.codeSystemEntityVersion csev" + " join csev.codeSystemEntity cse"
                + " left join cse.codeSystemVersionEntityMemberships csvem";
        //+ " left join fetch csvem.codeSystemVersion csv"
        //+ " left join fetch csv.codeSystem";

        Query q = hb_session.createQuery(hql);
        q.setCacheable(false);
        q.setCacheMode(CacheMode.IGNORE);
        //q.setHint("toplink.refresh", "true");

        hb_session.setCacheMode(CacheMode.IGNORE);
        hb_session.clear();
        hb_session.flush();

        List<de.fhdo.terminologie.db.hibernate.AssociationType> list = q.list();

        logger.debug("Anzahl: " + list.size());

        for (int i = 0; i < list.size(); ++i) {
            de.fhdo.terminologie.db.hibernate.AssociationType association = list.get(i);
            GenericListRowType row = createRowFromAssociation(association);

            dataList.add(row);
        }
    } catch (Exception e) {
        LoggingOutput.outputException(e, this);
    } finally {
        hb_session.close();
    }

    // Liste initialisieren
    Include inc = (Include) getFellow("incList");
    Window winGenericList = (Window) inc.getFellow("winGenericList");
    genericList = (GenericList) winGenericList;

    genericList.setListActions(this);
    genericList.setButton_new(true);
    genericList.setButton_edit(true);
    genericList.setButton_delete(true);
    genericList.setListHeader(header);
    genericList.setDataList(dataList);
}