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 Map properties , final ServiceName puServiceName , final DeploymentUnit deploymentUnit , final String scopedPuName , final String injectionTypeName , final SFSBXPCMap sfsbxpcMap , final PersistenceUnitMetadata pu ) { } 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 DeploymentUnit deploymentUnit ; private final PersistenceContextType type ; private final Map properties ; private final String unitName ; private final String injectionTypeName ; private final SFSBXPCMap sfsbxpcMap ; private final PersistenceUnitMetadata pu ; private static final String ENTITY_MANAGER_CLASS = "javax.persistence.EntityManager" ; public PersistenceContextJndiInjectable ( final ServiceName puServiceName , final DeploymentUnit deploymentUnit , final PersistenceContextType type , final Map properties , final String unitName , final String injectionTypeName , final SFSBXPCMap sfsbxpcMap , final PersistenceUnitMetadata pu ) { } @ Override public ManagedReference getReference ( ) { PersistenceUnitServiceImpl service = ( ( PersistenceUnitServiceImpl ) ( deploymentUnit . getServiceRegistry ( ) . 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 ) ; if ( JpaLogger . JPA_LOGGER . isDebugEnabled ( ) ) JpaLogger . JPA_LOGGER . debugf ( "created<seq2seq4repair_space>new<seq2seq4repair_space>TransactionScopedEntityManager<seq2seq4repair_space>for<seq2seq4repair_space>unit<seq2seq4repair_space>name=%s" , unitName ) ; } else { EntityManager entityManager1 = SFSBCallStack . findPersistenceContext ( unitName , sfsbxpcMap ) ; if ( entityManager1 == null ) { entityManager1 = emf . createEntityManager ( properties ) ; <START_BUG> entityManager = new org . jboss . as . jpa . container . ExtendedEntityManager ( unitName , entityManager1 ) ; <END_BUG> if ( JpaLogger . JPA_LOGGER . isDebugEnabled ( ) ) JpaLogger . JPA_LOGGER . debugf ( "created<seq2seq4repair_space>new<seq2seq4repair_space>ExtendedEntityManager<seq2seq4repair_space>for<seq2seq4repair_space>unit<seq2seq4repair_space>name=%s" , unitName ) ; } else { entityManager = entityManager1 ; if ( JpaLogger . JPA_LOGGER . isDebugEnabled ( ) ) JpaLogger . 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" , unitName ) ; } SFSBXPCMap . registerPersistenceContext ( entityManager ) ; SFSBCallStack . extendedPersistenceContextCreated ( unitName , entityManager ) ; } if ( ! standardEntityManager ) { Class extensionClass ; try { extensionClass = pu . getClassLoader ( ) . loadClass ( injectionTypeName ) ; } catch ( ClassNotFoundException e ) { throw JpaMessages . 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 ( JpaLogger . JPA_LOGGER . isDebugEnabled ( ) ) JpaLogger . 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:
entityManager = new org . jboss . as . jpa . container . ExtendedEntityManager ( unitName , entityManager1 , SFSBXPCMap . getApplicationDeploymentBagKeyName ( deploymentUnit ) ) ;