Buggy code:
@ SuppressWarnings ( "serial" ) public class JpaTransactionManager extends AbstractPlatformTransactionManager implements BeanFactoryAware , InitializingBean , ResourceTransactionManager { private EntityManagerFactory entityManagerFactory ; private String persistenceUnitName ; private final Map < String , Object > jpaPropertyMap = new HashMap < String , Object > ( ) ; private DataSource dataSource ; private JpaDialect jpaDialect = new DefaultJpaDialect ( ) ; public JpaTransactionManager ( ) { } public JpaTransactionManager ( EntityManagerFactory emf ) { } public void setEntityManagerFactory ( EntityManagerFactory emf ) { } public EntityManagerFactory getEntityManagerFactory ( ) { } public void setPersistenceUnitName ( String persistenceUnitName ) { } public String getPersistenceUnitName ( ) { } public void setJpaProperties ( Properties jpaProperties ) { } public void setJpaPropertyMap ( Map < String , ? > jpaProperties ) { } public Map < String , Object > getJpaPropertyMap ( ) { } public void setDataSource ( DataSource dataSource ) { } public DataSource getDataSource ( ) { } public void setJpaDialect ( JpaDialect jpaDialect ) { } public JpaDialect getJpaDialect ( ) { } @ Override public void setBeanFactory ( BeanFactory beanFactory ) throws BeansException { } @ Override public void afterPropertiesSet ( ) { } @ Override public Object getResourceFactory ( ) { } @ Override protected Object doGetTransaction ( ) { } @ Override protected boolean isExistingTransaction ( Object transaction ) { } @ Override protected void doBegin ( Object transaction , TransactionDefinition definition ) { JpaTransactionManager . JpaTransactionObject txObject = ( ( JpaTransactionManager . JpaTransactionObject ) ( transaction ) ) ; if ( ( txObject . hasConnectionHolder ( ) ) && ( ! ( txObject . getConnectionHolder ( ) . isSynchronizedWithTransaction ( ) ) ) ) { throw new IllegalTransactionStateException ( ( "Pre-bound<seq2seq4repair_space>JDBC<seq2seq4repair_space>Connection<seq2seq4repair_space>found!<seq2seq4repair_space>JpaTransactionManager<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>JpaTransactionManager<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>JPA<seq2seq4repair_space>or<seq2seq4repair_space>JDBC<seq2seq4repair_space>access." ) ) ) ; } try { if ( ( ( txObject . getEntityManagerHolder ( ) ) == null ) || ( txObject . getEntityManagerHolder ( ) . isSynchronizedWithTransaction ( ) ) ) { EntityManager newEm = createEntityManagerForTransaction ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( ( ( "Opened<seq2seq4repair_space>new<seq2seq4repair_space>EntityManager<seq2seq4repair_space>[" + newEm ) + "]<seq2seq4repair_space>for<seq2seq4repair_space>JPA<seq2seq4repair_space>transaction" ) ) ; } txObject . setEntityManagerHolder ( new EntityManagerHolder ( newEm ) , true ) ; } EntityManager em = txObject . getEntityManagerHolder ( ) . getEntityManager ( ) ; final int timeoutToUse = determineTimeout ( definition ) ; Object transactionData = getJpaDialect ( ) . beginTransaction ( em , new DelegatingTransactionDefinition ( definition ) { @ Override public int getTimeout ( ) { return timeoutToUse ; } } ) ; txObject . setTransactionData ( transactionData ) ; if ( timeoutToUse != ( TransactionDefinition . TIMEOUT_DEFAULT ) ) { txObject . getEntityManagerHolder ( ) . setTimeoutInSeconds ( timeoutToUse ) ; } if ( ( getDataSource ( ) ) != null ) { ConnectionHandle conHandle = getJpaDialect ( ) . getJdbcConnection ( em , definition . isReadOnly ( ) ) ; if ( conHandle != null ) { ConnectionHolder conHolder = new ConnectionHolder ( conHandle ) ; if ( timeoutToUse != ( TransactionDefinition . TIMEOUT_DEFAULT ) ) { conHolder . setTimeoutInSeconds ( timeoutToUse ) ; } if ( logger . isDebugEnabled ( ) ) { logger . debug ( ( ( "Exposing<seq2seq4repair_space>JPA<seq2seq4repair_space>transaction<seq2seq4repair_space>as<seq2seq4repair_space>JDBC<seq2seq4repair_space>transaction<seq2seq4repair_space>[" + ( conHolder . getConnectionHandle ( ) ) ) + "]" ) ) ; } TransactionSynchronizationManager . bindResource ( getDataSource ( ) , conHolder ) ; txObject . setConnectionHolder ( conHolder ) ; } else { if ( logger . isDebugEnabled ( ) ) { logger . debug ( ( ( ( ( "Not<seq2seq4repair_space>exposing<seq2seq4repair_space>JPA<seq2seq4repair_space>transaction<seq2seq4repair_space>[" + em ) + "]<seq2seq4repair_space>as<seq2seq4repair_space>JDBC<seq2seq4repair_space>transaction<seq2seq4repair_space>because<seq2seq4repair_space>JpaDialect<seq2seq4repair_space>[" ) + ( getJpaDialect ( ) ) ) + "]<seq2seq4repair_space>does<seq2seq4repair_space>not<seq2seq4repair_space>support<seq2seq4repair_space>JDBC<seq2seq4repair_space>Connection<seq2seq4repair_space>retrieval" ) ) ; } } } if ( txObject . isNewEntityManagerHolder ( ) ) { TransactionSynchronizationManager . bindResource ( getEntityManagerFactory ( ) , txObject . getEntityManagerHolder ( ) ) ; } txObject . getEntityManagerHolder ( ) . setSynchronizedWithTransaction ( true ) ; } catch ( TransactionException ex ) { closeEntityManagerAfterFailedBegin ( txObject ) ; throw ex ; <START_BUG> } catch ( Exception ex ) { <END_BUG> closeEntityManagerAfterFailedBegin ( txObject ) ; throw new CannotCreateTransactionException ( "Could<seq2seq4repair_space>not<seq2seq4repair_space>open<seq2seq4repair_space>JPA<seq2seq4repair_space>EntityManager<seq2seq4repair_space>for<seq2seq4repair_space>transaction" , ex ) ; } } protected EntityManager createEntityManagerForTransaction ( ) { } protected void closeEntityManagerAfterFailedBegin ( JpaTransactionManager . JpaTransactionObject txObject ) { } @ Override protected Object doSuspend ( Object transaction ) { } @ Override protected void doResume ( Object transaction , Object suspendedResources ) { } @ Override protected boolean shouldCommitOnGlobalRollbackOnly ( ) { } @ Override protected void doCommit ( DefaultTransactionStatus status ) { } @ Override protected void doRollback ( DefaultTransactionStatus status ) { } @ Override protected void doSetRollbackOnly ( DefaultTransactionStatus status ) { } @ Override protected void doCleanupAfterCompletion ( Object transaction ) { } private class JpaTransactionObject extends JdbcTransactionObjectSupport { private EntityManagerHolder entityManagerHolder ; private boolean newEntityManagerHolder ; private Object transactionData ; public void setEntityManagerHolder ( EntityManagerHolder entityManagerHolder , boolean newEntityManagerHolder ) { } public EntityManagerHolder getEntityManagerHolder ( ) { } public boolean isNewEntityManagerHolder ( ) { } public boolean hasTransaction ( ) { } public void setTransactionData ( Object transactionData ) { } public Object getTransactionData ( ) { } public void setRollbackOnly ( ) { } @ Override public boolean isRollbackOnly ( ) { } @ Override public void flush ( ) { } @ Override public Object createSavepoint ( ) throws TransactionException { } @ Override public void rollbackToSavepoint ( Object savepoint ) throws TransactionException { } @ Override public void releaseSavepoint ( Object savepoint ) throws TransactionException { } private SavepointManager getSavepointManager ( ) { } } private static class SuspendedResourcesHolder { private final EntityManagerHolder entityManagerHolder ; private final ConnectionHolder connectionHolder ; private SuspendedResourcesHolder ( EntityManagerHolder emHolder , ConnectionHolder conHolder ) { } private EntityManagerHolder getEntityManagerHolder ( ) { } private ConnectionHolder getConnectionHolder ( ) { } } }

Fix:
} catch ( Throwable ex ) {