Buggy code:
public class HibernateTransactionManager extends AbstractPlatformTransactionManager implements BeanFactoryAware , InitializingBean , ResourceTransactionManager { private SessionFactory sessionFactory ; private DataSource dataSource ; private boolean autodetectDataSource = true ; private boolean prepareConnection = true ; private boolean hibernateManagedSession = false ; private boolean earlyFlushBeforeCommit = false ; private Object entityInterceptor ; private SQLExceptionTranslator jdbcExceptionTranslator ; private SQLExceptionTranslator defaultJdbcExceptionTranslator ; private BeanFactory beanFactory ; public HibernateTransactionManager ( ) { } public HibernateTransactionManager ( SessionFactory sessionFactory ) { } public void setSessionFactory ( SessionFactory sessionFactory ) { } public SessionFactory getSessionFactory ( ) { } public void setDataSource ( DataSource dataSource ) { } public DataSource getDataSource ( ) { } public void setAutodetectDataSource ( boolean autodetectDataSource ) { } public void setPrepareConnection ( boolean prepareConnection ) { } public void setHibernateManagedSession ( boolean hibernateManagedSession ) { } public void setEarlyFlushBeforeCommit ( boolean earlyFlushBeforeCommit ) { } public void setEntityInterceptorBeanName ( String entityInterceptorBeanName ) { } public void setEntityInterceptor ( Interceptor entityInterceptor ) { } public Interceptor getEntityInterceptor ( ) throws IllegalStateException , BeansException { } public void setJdbcExceptionTranslator ( SQLExceptionTranslator jdbcExceptionTranslator ) { } public SQLExceptionTranslator getJdbcExceptionTranslator ( ) { } public void setBeanFactory ( BeanFactory beanFactory ) { } public void afterPropertiesSet ( ) { } public Object getResourceFactory ( ) { } @ Override protected Object doGetTransaction ( ) { } @ Override protected boolean isExistingTransaction ( Object transaction ) { } @ Override protected void doBegin ( Object transaction , TransactionDefinition definition ) { HibernateTransactionManager . HibernateTransactionObject txObject = ( ( HibernateTransactionManager . HibernateTransactionObject ) ( transaction ) ) ; if ( ( txObject . hasConnectionHolder ( ) ) && ( ! ( txObject . getConnectionHolder ( ) . isSynchronizedWithTransaction ( ) ) ) ) { throw new IllegalTransactionStateException ( ( "Pre-bound<seq2seq4repair_space>JDBC<seq2seq4repair_space>Connection<seq2seq4repair_space>found!<seq2seq4repair_space>HibernateTransactionManager<seq2seq4repair_space>does<seq2seq4repair_space>not<seq2seq4repair_space>support<seq2seq4repair_space>" + ( ( "running<seq2seq4repair_space>within<seq2seq4repair_space>DataSourceTransactionManager<seq2seq4repair_space>if<seq2seq4repair_space>told<seq2seq4repair_space>to<seq2seq4repair_space>manage<seq2seq4repair_space>the<seq2seq4repair_space>DataSource<seq2seq4repair_space>itself.<seq2seq4repair_space>" + "It<seq2seq4repair_space>is<seq2seq4repair_space>recommended<seq2seq4repair_space>to<seq2seq4repair_space>use<seq2seq4repair_space>a<seq2seq4repair_space>single<seq2seq4repair_space>HibernateTransactionManager<seq2seq4repair_space>for<seq2seq4repair_space>all<seq2seq4repair_space>transactions<seq2seq4repair_space>" ) + "on<seq2seq4repair_space>a<seq2seq4repair_space>single<seq2seq4repair_space>DataSource,<seq2seq4repair_space>no<seq2seq4repair_space>matter<seq2seq4repair_space>whether<seq2seq4repair_space>Hibernate<seq2seq4repair_space>or<seq2seq4repair_space>JDBC<seq2seq4repair_space>access." ) ) ) ; } Session session = null ; try { if ( ( ( txObject . getSessionHolder ( ) ) == null ) || ( txObject . getSessionHolder ( ) . isSynchronizedWithTransaction ( ) ) ) { Interceptor entityInterceptor = getEntityInterceptor ( ) ; Session newSession = ( entityInterceptor != null ) ? getSessionFactory ( ) . openSession ( entityInterceptor ) : getSessionFactory ( ) . openSession ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( ( ( "Opened<seq2seq4repair_space>new<seq2seq4repair_space>Session<seq2seq4repair_space>[" + ( SessionFactoryUtils . toString ( newSession ) ) ) + "]<seq2seq4repair_space>for<seq2seq4repair_space>Hibernate<seq2seq4repair_space>transaction" ) ) ; } txObject . setSession ( newSession ) ; } session = txObject . getSessionHolder ( ) . getSession ( ) ; if ( ( this . prepareConnection ) && ( isSameConnectionForEntireSession ( session ) ) ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( ( ( "Preparing<seq2seq4repair_space>JDBC<seq2seq4repair_space>Connection<seq2seq4repair_space>of<seq2seq4repair_space>Hibernate<seq2seq4repair_space>Session<seq2seq4repair_space>[" + ( SessionFactoryUtils . toString ( session ) ) ) + "]" ) ) ; } Connection con = session . connection ( ) ; Integer previousIsolationLevel = DataSourceUtils . prepareConnectionForTransaction ( con , definition ) ; txObject . setPreviousIsolationLevel ( previousIsolationLevel ) ; } else { if ( ( definition . getIsolationLevel ( ) ) != ( TransactionDefinition . ISOLATION_DEFAULT ) ) { throw new InvalidIsolationLevelException ( ( "HibernateTransactionManager<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>allowed<seq2seq4repair_space>to<seq2seq4repair_space>support<seq2seq4repair_space>custom<seq2seq4repair_space>isolation<seq2seq4repair_space>levels:<seq2seq4repair_space>" + ( ( ( "make<seq2seq4repair_space>sure<seq2seq4repair_space>that<seq2seq4repair_space>its<seq2seq4repair_space>'prepareConnection'<seq2seq4repair_space>flag<seq2seq4repair_space>is<seq2seq4repair_space>on<seq2seq4repair_space>(the<seq2seq4repair_space>default)<seq2seq4repair_space>and<seq2seq4repair_space>that<seq2seq4repair_space>the<seq2seq4repair_space>" + "Hibernate<seq2seq4repair_space>connection<seq2seq4repair_space>release<seq2seq4repair_space>mode<seq2seq4repair_space>is<seq2seq4repair_space>set<seq2seq4repair_space>to<seq2seq4repair_space>'on_close'<seq2seq4repair_space>(SpringTransactionFactory's<seq2seq4repair_space>default).<seq2seq4repair_space>" ) + "Make<seq2seq4repair_space>sure<seq2seq4repair_space>that<seq2seq4repair_space>your<seq2seq4repair_space>LocalSessionFactoryBean<seq2seq4repair_space>actually<seq2seq4repair_space>uses<seq2seq4repair_space>SpringTransactionFactory:<seq2seq4repair_space>Your<seq2seq4repair_space>" ) + "Hibernate<seq2seq4repair_space>properties<seq2seq4repair_space>should<seq2seq4repair_space>*not*<seq2seq4repair_space>include<seq2seq4repair_space>a<seq2seq4repair_space>'hibernate.transaction.factory_class'<seq2seq4repair_space>property!" ) ) ) ; } if ( logger . isDebugEnabled ( ) ) { logger . debug ( ( ( "Not<seq2seq4repair_space>preparing<seq2seq4repair_space>JDBC<seq2seq4repair_space>Connection<seq2seq4repair_space>of<seq2seq4repair_space>Hibernate<seq2seq4repair_space>Session<seq2seq4repair_space>[" + ( SessionFactoryUtils . toString ( session ) ) ) + "]" ) ) ; } } if ( ( definition . isReadOnly ( ) ) && ( txObject . isNewSession ( ) ) ) { session . setFlushMode ( MANUAL ) ; } if ( ( ! ( definition . isReadOnly ( ) ) ) && ( ! ( txObject . isNewSession ( ) ) ) ) { FlushMode flushMode = session . getFlushMode ( ) ; if ( flushMode . lessThan ( COMMIT ) ) { session . setFlushMode ( AUTO ) ; txObject . getSessionHolder ( ) . setPreviousFlushMode ( flushMode ) ; } } <START_BUG> Transaction hibTx = null ; <END_BUG> int timeout = determineTimeout ( definition ) ; if ( timeout != ( TransactionDefinition . TIMEOUT_DEFAULT ) ) { hibTx = session . getTransaction ( ) ; hibTx . setTimeout ( timeout ) ; hibTx . begin ( ) ; } else { hibTx = session . beginTransaction ( ) ; } txObject . getSessionHolder ( ) . setTransaction ( hibTx ) ; if ( ( getDataSource ( ) ) != null ) { Connection con = session . connection ( ) ; ConnectionHolder conHolder = new ConnectionHolder ( con ) ; if ( timeout != ( TransactionDefinition . TIMEOUT_DEFAULT ) ) { conHolder . setTimeoutInSeconds ( timeout ) ; } if ( logger . isDebugEnabled ( ) ) { logger . debug ( ( ( "Exposing<seq2seq4repair_space>Hibernate<seq2seq4repair_space>transaction<seq2seq4repair_space>as<seq2seq4repair_space>JDBC<seq2seq4repair_space>transaction<seq2seq4repair_space>[" + con ) + "]" ) ) ; } TransactionSynchronizationManager . bindResource ( getDataSource ( ) , conHolder ) ; txObject . setConnectionHolder ( conHolder ) ; } if ( txObject . isNewSessionHolder ( ) ) { TransactionSynchronizationManager . bindResource ( getSessionFactory ( ) , txObject . getSessionHolder ( ) ) ; } txObject . getSessionHolder ( ) . setSynchronizedWithTransaction ( true ) ; } catch ( Exception ex ) { if ( txObject . isNewSession ( ) ) { try { if ( session . getTransaction ( ) . isActive ( ) ) { session . getTransaction ( ) . rollback ( ) ; } } catch ( Throwable ex2 ) { logger . debug ( "Could<seq2seq4repair_space>not<seq2seq4repair_space>rollback<seq2seq4repair_space>Session<seq2seq4repair_space>after<seq2seq4repair_space>failed<seq2seq4repair_space>transaction<seq2seq4repair_space>begin" , ex ) ; } finally { SessionFactoryUtils . closeSession ( session ) ; } } throw new CannotCreateTransactionException ( "Could<seq2seq4repair_space>not<seq2seq4repair_space>open<seq2seq4repair_space>Hibernate<seq2seq4repair_space>Session<seq2seq4repair_space>for<seq2seq4repair_space>transaction" , ex ) ; } } @ Override protected Object doSuspend ( Object transaction ) { } @ Override protected void doResume ( Object transaction , Object suspendedResources ) { } @ Override protected void prepareForCommit ( DefaultTransactionStatus status ) { } @ Override protected void doCommit ( DefaultTransactionStatus status ) { }

Fix:
Transaction hibTx ;