List of usage examples for org.hibernate.engine.spi SessionImplementor getHibernateFlushMode
FlushMode getHibernateFlushMode();
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(); } }