Buggy code:
public class PersistenceContextInjectionSource extends InjectionSource { private final PersistenceContextType type ; private final PersistenceContextInjectionSource . PersistenceContextJndiInjectable injectable ; private final ServiceName puServiceName ; public PersistenceContextInjectionSource ( final PersistenceContextType type , final SynchronizationType synchronizationType , final Map properties , final ServiceName puServiceName , final ServiceRegistry serviceRegistry , final String scopedPuName , final String injectionTypeName , final PersistenceUnitMetadata pu , final JPADeploymentSettings jpaDeploymentSettings ) { } public void getResourceValue ( final ResolutionContext resolutionContext , final ServiceBuilder < ? > serviceBuilder , final DeploymentPhaseContext phaseContext , final Injector < ManagedReferenceFactory > injector ) throws DeploymentUnitProcessingException { } public boolean equals ( Object other ) { } public int hashCode ( ) { } private static final class PersistenceContextJndiInjectable implements ManagedReferenceFactory { private final ServiceName puServiceName ; private final ServiceRegistry serviceRegistry ; private final PersistenceContextType type ; private final SynchronizationType synchronizationType ; private final Map properties ; private final String unitName ; private final String injectionTypeName ; private final PersistenceUnitMetadata pu ; private final JPADeploymentSettings jpaDeploymentSettings ; private static final String ENTITY_MANAGER_CLASS = "javax.persistence.EntityManager" ; public PersistenceContextJndiInjectable ( final ServiceName puServiceName , final ServiceRegistry serviceRegistry , final PersistenceContextType type , SynchronizationType synchronizationType , final Map properties , final String unitName , final String injectionTypeName , final PersistenceUnitMetadata pu , final JPADeploymentSettings jpaDeploymentSettings ) { } @ Override public ManagedReference getReference ( ) { PersistenceUnitServiceImpl service = ( ( PersistenceUnitServiceImpl ) ( serviceRegistry . getRequiredService ( puServiceName ) . getValue ( ) ) ) ; EntityManagerFactory emf = service . getEntityManagerFactory ( ) ; EntityManager entityManager ; boolean standardEntityManager = PersistenceContextInjectionSource . PersistenceContextJndiInjectable . ENTITY_MANAGER_CLASS . equals ( injectionTypeName ) ; if ( type . equals ( TRANSACTION ) ) { entityManager = new org . jboss . as . jpa . container . TransactionScopedEntityManager ( unitName , properties , emf , synchronizationType ) ; if ( JPA_LOGGER . isDebugEnabled ( ) ) JPA_LOGGER . debugf ( "created<seq2seq4repair_space>new<seq2seq4repair_space>TransactionScopedEntityManager<seq2seq4repair_space>for<seq2seq4repair_space>unit<seq2seq4repair_space>name=%s" , unitName ) ; } else { boolean useDeepInheritance = ! ( SHALLOW . equals ( JPAService . getDefaultExtendedPersistenceInheritance ( ) ) ) ; if ( ( jpaDeploymentSettings ) != null ) { useDeepInheritance = DEEP . equals ( jpaDeploymentSettings . getExtendedPersistenceInheritanceType ( ) ) ; } boolean createdNewExtendedPersistence = false ; ExtendedEntityManager entityManager1 ; if ( useDeepInheritance ) { entityManager1 = INSTANCE . findExtendedPersistenceContext ( unitName ) ; } else { entityManager1 = ExtendedPersistenceShallowInheritance . INSTANCE . findExtendedPersistenceContext ( unitName ) ; } if ( entityManager1 == null ) { <START_BUG> entityManager1 = new ExtendedEntityManager ( unitName , emf . createEntityManager ( properties ) ) ; <END_BUG> createdNewExtendedPersistence = true ; if ( JPA_LOGGER . isDebugEnabled ( ) ) JPA_LOGGER . debugf ( "created<seq2seq4repair_space>new<seq2seq4repair_space>ExtendedEntityManager<seq2seq4repair_space>for<seq2seq4repair_space>unit<seq2seq4repair_space>name=%s,<seq2seq4repair_space>useDeepInheritance<seq2seq4repair_space>=<seq2seq4repair_space>%b" , unitName , useDeepInheritance ) ; } else { entityManager1 . increaseReferenceCount ( ) ; if ( JPA_LOGGER . isDebugEnabled ( ) ) JPA_LOGGER . debugf ( ( "inherited<seq2seq4repair_space>existing<seq2seq4repair_space>ExtendedEntityManager<seq2seq4repair_space>from<seq2seq4repair_space>SFSB<seq2seq4repair_space>invocation<seq2seq4repair_space>stack,<seq2seq4repair_space>unit<seq2seq4repair_space>name=%s,<seq2seq4repair_space>" + "%d<seq2seq4repair_space>beans<seq2seq4repair_space>sharing<seq2seq4repair_space>ExtendedEntityManager,<seq2seq4repair_space>useDeepInheritance<seq2seq4repair_space>=<seq2seq4repair_space>%b" ) , unitName , entityManager1 . getReferenceCount ( ) , useDeepInheritance ) ; } entityManager = entityManager1 ; CreatedEntityManagers . registerPersistenceContext ( entityManager1 ) ; if ( createdNewExtendedPersistence ) { if ( useDeepInheritance ) { INSTANCE . registerExtendedPersistenceContext ( unitName , entityManager1 ) ; } else { ExtendedPersistenceShallowInheritance . INSTANCE . registerExtendedPersistenceContext ( unitName , entityManager1 ) ; } } } if ( ! standardEntityManager ) { Class extensionClass ; try { extensionClass = pu . getClassLoader ( ) . loadClass ( injectionTypeName ) ; } catch ( ClassNotFoundException e ) { throw MESSAGES . cannotLoadFromJpa ( e , injectionTypeName ) ; } Object targetValueToInject = entityManager . unwrap ( extensionClass ) ; Class [ ] targetInterfaces = targetValueToInject . getClass ( ) . getInterfaces ( ) ; Class [ ] proxyInterfaces = new Class [ ( targetInterfaces . length ) + 1 ] ; boolean alreadyHasInterfaceClass = false ; for ( int interfaceIndex = 0 ; interfaceIndex < ( targetInterfaces . length ) ; interfaceIndex ++ ) { Class interfaceClass = targetInterfaces [ interfaceIndex ] ; if ( interfaceClass . equals ( extensionClass ) ) { proxyInterfaces = targetInterfaces ; alreadyHasInterfaceClass = true ; break ; } proxyInterfaces [ ( 1 + interfaceIndex ) ] = interfaceClass ; } if ( ! alreadyHasInterfaceClass ) { proxyInterfaces [ 0 ] = extensionClass ; } EntityManagerUnwrappedTargetInvocationHandler entityManagerUnwrappedTargetInvocationHandler = new EntityManagerUnwrappedTargetInvocationHandler ( entityManager , extensionClass ) ; Object proxyForUnwrappedObject = Proxy . newProxyInstance ( extensionClass . getClassLoader ( ) , proxyInterfaces , entityManagerUnwrappedTargetInvocationHandler ) ; if ( JPA_LOGGER . isDebugEnabled ( ) ) JPA_LOGGER . debugf ( "injecting<seq2seq4repair_space>entity<seq2seq4repair_space>manager<seq2seq4repair_space>into<seq2seq4repair_space>a<seq2seq4repair_space>'%s'<seq2seq4repair_space>(unit<seq2seq4repair_space>name=%s)" , extensionClass . getName ( ) , unitName ) ; return new ValueManagedReference ( new org . jboss . msc . value . ImmediateValue < Object > ( proxyForUnwrappedObject ) ) ; } return new ValueManagedReference ( new org . jboss . msc . value . ImmediateValue < Object > ( entityManager ) ) ; } } }

Fix:
entityManager1 = new ExtendedEntityManager ( unitName , emf . createEntityManager ( properties ) , synchronizationType ) ;