public Session getSession() { RuntimeConfig config = RuntimeConfig.getCurrentInstance( intactSession ); DaoFactory daoFactory = DaoFactory.getCurrentInstance( intactSession, config.getDefaultDataConfig() ); if ( !daoFactory.isTransactionActive() ) { if ( config.isAutoBeginTransaction() ) { log.debug( "Auto starting transaction" ); daoFactory.beginTransaction(); // starts or uses an existing transaction } else { throw new AutoBeginTransactionException( "You must begin a transaction manually." ); } } // invoking the method from the session factory because if the session is closed it will automatically // open one return session.getSessionFactory().getCurrentSession(); }