public Connection close() throws HibernateException { log.trace( "closing session" ); if ( factory.getStatistics().isStatisticsEnabled() ) factory.getStatisticsImplementor().closeSession(); try { try { if ( childSessionsByEntityMode != null ) { Iterator childSessions = childSessionsByEntityMode.values().iterator(); while ( childSessions.hasNext() ) { final SessionImpl child = ( SessionImpl ) childSessions.next(); child.close(); } } } catch( Throwable t ) { // just ignore } if ( isRootSession ) { return jdbcContext.getConnectionManager().close(); } else { return null; } } finally { closed = true; cleanup(); } }