Example usage for org.hibernate Session setFlushMode

List of usage examples for org.hibernate Session setFlushMode

Introduction

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

Prototype

@Deprecated
void setFlushMode(FlushMode flushMode);

Source Link

Document

Set the flush mode for this session.

Usage

From source file:service.DatabaseService.java

@Override
public List listEntityByJoinCriteria(String table, String propertyName, String criteria_column,
        String criteria_text) {/*  w w w.  j  a  v  a  2 s .c o m*/
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory();

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

    String table_cap = table.substring(0, 1).toUpperCase() + table.substring(1);

    //String str_query = "select u from  Users u join u.userRoleses r where r.role='ROLE_ADMIN'";
    String str_query = "select u from " + table_cap + " u join u. " + propertyName + " r where r."
            + criteria_column + "='" + criteria_text + "'";

    Query query = session.createQuery(str_query);

    //ManagedSessionContext.unbind(sessionFactory);
    session.flush();
    List aux = query.list();
    return query.list();
}

From source file:service.DatabaseService.java

@Override
public List listEntityByJoinIdCriteria(String table, String propertyName, String criteria_column, Integer id,
        String sndC, Integer sndQ) {
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory();

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

    String table_cap = table.substring(0, 1).toUpperCase() + table.substring(1);

    //String str_query = "select u from  Users u join u.userRoleses r where r.role='ROLE_ADMIN'";
    String str_query = "select u from " + table_cap + " u join u. " + propertyName + " r where r."
            + criteria_column + "=" + id + "AND u." + sndC + "=" + sndQ;

    Query query = session.createQuery(str_query);

    //ManagedSessionContext.unbind(sessionFactory);
    session.flush();//from   w  ww.j av a  2  s.com
    List aux = query.list();
    return query.list();
}

From source file:service.DatabaseService.java

public void deleteEntity(Object entity) {
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory();

    //Session session = sessionFactory.openSession();
    Session session = sessionFactory.getCurrentSession();
    session.setFlushMode(FlushMode.MANUAL);
    //ManagedSessionContext.bind(session);
    Transaction tx = null;/* ww w.  ja  v  a  2 s  . c  o  m*/

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

From source file:service.DatabaseService.java

@Override
public List listEntityPartialQuery(String table, ArrayList<String> columns, String query_text) {
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory();

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

    String table_capitalized = table.substring(0, 1).toUpperCase() + table.substring(1);

    int cols = columns.size();

    String str_query = "from " + table_capitalized + " where ";
    for (int i = 0; i < cols; i++) {

        str_query += columns.get(i) + " like :crit";
        if (i < cols - 1)
            str_query += " or ";
    }//  w  ww  .  ja  v a 2 s .  c  o  m

    Query query = session.createQuery(str_query);
    query.setParameter("crit", "%" + query_text + "%");

    session.flush();

    return query.list();
}

From source file:won.protocol.util.hibernate.FlushModeSettingHibernateJpaDialect.java

License:Apache License

public Object prepareTransaction(EntityManager entityManager, boolean readOnly, String name)
        throws PersistenceException {

    Session session = getSession(entityManager);
    FlushMode currentFlushMode = session.getFlushMode();
    FlushMode previousFlushMode = null;/*w ww .  ja v  a  2  s.  co  m*/
    if (getFlushMode() != null) {
        session.setFlushMode(flushMode);
        previousFlushMode = currentFlushMode;
    } else if (readOnly) {
        // We should suppress flushing for a read-only transaction.
        session.setFlushMode(FlushMode.MANUAL);
        previousFlushMode = currentFlushMode;
    } else {
        // We need AUTO or COMMIT for a non-read-only transaction.
        if (currentFlushMode.lessThan(FlushMode.COMMIT)) {
            session.setFlushMode(FlushMode.AUTO);
            previousFlushMode = currentFlushMode;
        }
    }
    return new SessionTransactionData(session, previousFlushMode);
}