Buggy code:
public abstract class SessionFactoryUtils { public static final int SESSION_SYNCHRONIZATION_ORDER = ( DataSourceUtils . CONNECTION_SYNCHRONIZATION_ORDER ) - 100 ; static final Log logger = LogFactory . getLog ( SessionFactoryUtils . class ) ; private static final ThreadLocal < Map < SessionFactory , Set < Session > > > deferredCloseHolder = new org . springframework . core . NamedThreadLocal < Map < SessionFactory , Set < Session > > > ( "Hibernate<seq2seq4repair_space>Sessions<seq2seq4repair_space>registered<seq2seq4repair_space>for<seq2seq4repair_space>deferred<seq2seq4repair_space>close" ) ; public static DataSource getDataSource ( SessionFactory sessionFactory ) { } public static SQLExceptionTranslator newJdbcExceptionTranslator ( SessionFactory sessionFactory ) { } public static TransactionManager getJtaTransactionManager ( SessionFactory sessionFactory , Session session ) { } public static Session getSession ( SessionFactory sessionFactory , boolean allowCreate ) throws IllegalStateException , DataAccessResourceFailureException { } public static Session getSession ( SessionFactory sessionFactory , Interceptor entityInterceptor , SQLExceptionTranslator jdbcExceptionTranslator ) throws DataAccessResourceFailureException { } public static Session doGetSession ( SessionFactory sessionFactory , boolean allowCreate ) throws IllegalStateException , HibernateException { } private static Session doGetSession ( SessionFactory sessionFactory , Interceptor entityInterceptor , SQLExceptionTranslator jdbcExceptionTranslator , boolean allowCreate ) throws IllegalStateException , HibernateException { } private static Session getJtaSynchronizedSession ( SessionHolder sessionHolder , SessionFactory sessionFactory , SQLExceptionTranslator jdbcExceptionTranslator ) throws DataAccessResourceFailureException { } private static void registerJtaSynchronization ( Session session , SessionFactory sessionFactory , SQLExceptionTranslator jdbcExceptionTranslator , SessionHolder sessionHolder ) { } public static Session getNewSession ( SessionFactory sessionFactory ) { } public static Session getNewSession ( SessionFactory sessionFactory , Interceptor entityInterceptor ) { } public static String toString ( Session session ) { } public static boolean hasTransactionalSession ( SessionFactory sessionFactory ) { } public static boolean isSessionTransactional ( Session session , SessionFactory sessionFactory ) { } public static void applyTransactionTimeout ( Query query , SessionFactory sessionFactory ) { } public static void applyTransactionTimeout ( Criteria criteria , SessionFactory sessionFactory ) { } public static DataAccessException convertHibernateAccessException ( HibernateException ex ) { } public static boolean isDeferredCloseActive ( SessionFactory sessionFactory ) { } public static void initDeferredClose ( SessionFactory sessionFactory ) { } public static void processDeferredClose ( SessionFactory sessionFactory ) { Assert . notNull ( sessionFactory , "No<seq2seq4repair_space>SessionFactory<seq2seq4repair_space>specified" ) ; Map < SessionFactory , Set < Session > > holderMap = SessionFactoryUtils . deferredCloseHolder . get ( ) ; if ( ( holderMap == null ) || ( ! ( holderMap . containsKey ( sessionFactory ) ) ) ) { throw new IllegalStateException ( ( ( "Deferred<seq2seq4repair_space>close<seq2seq4repair_space>not<seq2seq4repair_space>active<seq2seq4repair_space>for<seq2seq4repair_space>SessionFactory<seq2seq4repair_space>[" + sessionFactory ) + "]" ) ) ; } SessionFactoryUtils . logger . debug ( "Processing<seq2seq4repair_space>deferred<seq2seq4repair_space>close<seq2seq4repair_space>of<seq2seq4repair_space>Hibernate<seq2seq4repair_space>Sessions" ) ; Set < Session > sessions = holderMap . remove ( sessionFactory ) ; for ( Session session : sessions ) { SessionFactoryUtils . closeSession ( session ) ; } if ( holderMap . isEmpty ( ) ) { <START_BUG> SessionFactoryUtils . deferredCloseHolder . set ( null ) ; <END_BUG> } } public static void releaseSession ( Session session , SessionFactory sessionFactory ) { } static void closeSessionOrRegisterDeferredClose ( Session session , SessionFactory sessionFactory ) { } public static void closeSession ( Session session ) { } }

Fix:
SessionFactoryUtils . deferredCloseHolder . remove ( ) ;