Example usage for org.hibernate ConnectionReleaseMode AFTER_TRANSACTION

List of usage examples for org.hibernate ConnectionReleaseMode AFTER_TRANSACTION

Introduction

In this page you can find the example usage for org.hibernate ConnectionReleaseMode AFTER_TRANSACTION.

Prototype

ConnectionReleaseMode AFTER_TRANSACTION

To view the source code for org.hibernate ConnectionReleaseMode AFTER_TRANSACTION.

Click Source Link

Document

Indicates that JDBC connections should be released after each transaction ends (works with both JTA-registered synch and HibernateTransaction API).

Usage

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

License:Open Source License

public void doBeforeTransactionCompletion(SessionImplementor session) {
    if (workUnits.size() == 0) {
        return;//from  w  w  w.  jav a2  s.c om
    }
    if (!isMarkedForRollback(auditedSession)) {
        try {
            if (FlushMode.isManualFlushMode(auditedSession.getFlushMode())) {
                Session temporarySession = null;
                try {
                    temporarySession = ((Session) session).sessionWithOptions().transactionContext()
                            .autoClose(false).connectionReleaseMode(ConnectionReleaseMode.AFTER_TRANSACTION)
                            .openSession();
                    executeInSession(temporarySession);
                    temporarySession.flush();
                } finally {
                    if (temporarySession != null) {
                        temporarySession.close();
                    }
                }
            } else {
                auditedSession.flush();
                executeInSession(auditedSession);
            }
        } catch (RuntimeException e) {
            if (log.isErrorEnabled()) {
                log.error("RuntimeException occurred in beforeCompletion, will rollback and re-throw exception",
                        e);
            }
            rollback();
            throw e;
        }
    }
}

From source file:org.xerela.zap.hibernate.internal.ZTransactionFactory.java

License:Mozilla Public License

/** {@inheritDoc} */
public ConnectionReleaseMode getDefaultReleaseMode() {
    return ConnectionReleaseMode.AFTER_TRANSACTION; //AFTER_STATEMENT;
}