Example usage for org.hibernate FlushMode MANUAL

List of usage examples for org.hibernate FlushMode MANUAL

Introduction

In this page you can find the example usage for org.hibernate FlushMode MANUAL.

Prototype

FlushMode MANUAL

To view the source code for org.hibernate FlushMode MANUAL.

Click Source Link

Document

The Session is only ever flushed when Session#flush is explicitly called by the application.

Usage

From source file:uk.org.openeyes.DatabaseFunctions.java

/**
 *
 *//*w  ww  .ja  va 2  s . c o m*/
public void setSession() {
    if (this.session == null || !(this.session.isConnected())) {
        try {
            this.session = sessionFactory.openSession();
        } catch (Exception e) {
            System.exit(5);
        }
        session.setFlushMode(FlushMode.MANUAL);
        ManagedSessionContext.bind(session);
    }
}

From source file:woko.ext.usermanagement.hibernate.HibernateUserManager.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
public U getUserByUsername(String username) {
    Session s = hibernateStore.getSession();
    List l = s.createCriteria(getUserClass()).add(Restrictions.eq("username", username))
            .setFlushMode(FlushMode.MANUAL).list();
    if (l.size() == 0) {
        return null;
    }//from   w  w w  .j  a  v a2 s  .  c o  m
    if (l.size() > 1) {
        throw new IllegalStateException("more than 1 users with username==" + username);
    }
    return (U) l.get(0);
}

From source file:woko.ext.usermanagement.hibernate.HibernateUserManager.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
public U getUserByEmail(String email) {
    Session s = hibernateStore.getSession();
    List l = s.createCriteria(getUserClass()).add(Restrictions.eq("email", email))
            .setFlushMode(FlushMode.MANUAL).list();
    if (l.size() == 0) {
        return null;
    }//from   w w  w  .  ja  v  a 2  s. c om
    if (l.size() > 1) {
        throw new IllegalStateException("more than 1 users with email==" + email);
    }
    return (U) l.get(0);
}

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;//from www. ja v a  2s . c o  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);
}