Buggy code:
public abstract class AbstractEntityManagerFactoryBean implements BeanClassLoaderAware , DisposableBean , FactoryBean , InitializingBean , PersistenceExceptionTranslator , EntityManagerFactoryInfo { protected final Log logger = LogFactory . getLog ( getClass ( ) ) ; private PersistenceProvider persistenceProvider ; private String persistenceUnitName ; private final Map < String , Object > jpaPropertyMap = new HashMap < String , Object > ( ) ; private Class < ? extends EntityManagerFactory > entityManagerFactoryInterface ; private Class < ? extends EntityManager > entityManagerInterface ; private JpaDialect jpaDialect ; private JpaVendorAdapter jpaVendorAdapter ; private ClassLoader beanClassLoader = getClass ( ) . getClassLoader ( ) ; public EntityManagerFactory nativeEntityManagerFactory ; private EntityManagerFactory entityManagerFactory ; public void setPersistenceProviderClass ( Class < ? extends PersistenceProvider > persistenceProviderClass ) { } public void setPersistenceProvider ( PersistenceProvider persistenceProvider ) { } public PersistenceProvider getPersistenceProvider ( ) { } 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 setEntityManagerFactoryInterface ( Class < ? extends EntityManagerFactory > emfInterface ) { } public void setEntityManagerInterface ( Class < ? extends EntityManager > emInterface ) { } public Class < ? extends EntityManager > getEntityManagerInterface ( ) { } public void setJpaDialect ( JpaDialect jpaDialect ) { } public JpaDialect getJpaDialect ( ) { } public void setJpaVendorAdapter ( JpaVendorAdapter jpaVendorAdapter ) { } public JpaVendorAdapter getJpaVendorAdapter ( ) { } public void setBeanClassLoader ( ClassLoader classLoader ) { } public ClassLoader getBeanClassLoader ( ) { } public final void afterPropertiesSet ( ) throws PersistenceException { } protected EntityManagerFactory createEntityManagerFactoryProxy ( EntityManagerFactory emf ) { } protected abstract EntityManagerFactory createNativeEntityManagerFactory ( ) throws PersistenceException { } public DataAccessException translateExceptionIfPossible ( RuntimeException ex ) { } public EntityManagerFactory getNativeEntityManagerFactory ( ) { } public PersistenceUnitInfo getPersistenceUnitInfo ( ) { } public DataSource getDataSource ( ) { } public EntityManagerFactory getObject ( ) { } public Class getObjectType ( ) { } public boolean isSingleton ( ) { } public void destroy ( ) { } private static class ManagedEntityManagerFactoryInvocationHandler implements InvocationHandler { private final EntityManagerFactory targetEntityManagerFactory ; private final EntityManagerFactoryInfo entityManagerFactoryInfo ; private final EntityManagerFactoryPlusOperations entityManagerFactoryPlusOperations ; public ManagedEntityManagerFactoryInvocationHandler ( EntityManagerFactory targetEmf , EntityManagerFactoryInfo emfInfo , EntityManagerFactoryPlusOperations entityManagerFactoryPlusOperations ) { } public Object invoke ( Object proxy , Method method , Object [ ] args ) throws Throwable { try { if ( method . getName ( ) . equals ( "equals" ) ) { <START_BUG> return proxy == ( args [ 0 ] ) ? Boolean . TRUE : Boolean . FALSE ; <END_BUG> } else if ( method . getName ( ) . equals ( "hashCode" ) ) { return System . identityHashCode ( proxy ) ; } else if ( method . getDeclaringClass ( ) . isAssignableFrom ( EntityManagerFactoryInfo . class ) ) { return method . invoke ( this . entityManagerFactoryInfo , args ) ; } else if ( method . getDeclaringClass ( ) . equals ( EntityManagerFactoryPlusOperations . class ) ) { return method . invoke ( this . entityManagerFactoryPlusOperations , args ) ; } Object retVal = method . invoke ( this . targetEntityManagerFactory , args ) ; if ( retVal instanceof EntityManager ) { EntityManager rawEntityManager = ( ( EntityManager ) ( retVal ) ) ; retVal = ExtendedEntityManagerCreator . createApplicationManagedEntityManager ( rawEntityManager , this . entityManagerFactoryInfo ) ; } return retVal ; } catch ( InvocationTargetException ex ) { throw ex . getTargetException ( ) ; } } } }

Fix:
return proxy == ( args [ 0 ] ) ;