Example usage for org.hibernate.engine.spi SessionImplementor getHibernateFlushMode

List of usage examples for org.hibernate.engine.spi SessionImplementor getHibernateFlushMode

Introduction

In this page you can find the example usage for org.hibernate.engine.spi SessionImplementor getHibernateFlushMode.

Prototype

FlushMode getHibernateFlushMode();

Source Link

Document

Get the current flush mode for this session.

Usage

From source file:com.googlecode.hibernate.audit.synchronization.AuditProcess.java

License:Open Source License

public void doBeforeTransactionCompletion(SessionImplementor session) {
    if (workUnits.size() == 0) {
        return;/*from ww  w. ja  v  a  2  s  .  c  o m*/
    }

    if (!session.getTransactionCoordinator().isActive()) {
        log.debug(
                "Skipping hibernate-audit transaction hook due to non-active (most likely marked as rollback) transaction");
        return;
    }

    if (FlushMode.MANUAL == session.getHibernateFlushMode() || session.isClosed()) {
        Session temporarySession = null;
        try {
            temporarySession = session.sessionWithOptions().connection().autoClose(false)
                    .connectionHandlingMode(
                            PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION)
                    .openSession();
            executeInSession(temporarySession);
            temporarySession.flush();
        } finally {
            if (temporarySession != null) {
                temporarySession.close();
            }
        }
    } else {
        executeInSession(session);

        // explicitly flushing the session, as the auto-flush may have already happened.
        session.flush();
    }
}