entityManager = new TransactionScopedEntityManager(unitName, properties, emf);
if (JPA_LOGGER.isDebugEnabled())
JPA_LOGGER.debugf("created new TransactionScopedEntityManager for unit name=%s", unitName);
} else {
// handle PersistenceContextType.EXTENDED
ReferenceCountedEntityManager entityManager1 = SFSBCallStack.findPersistenceContext(unitName);
if (entityManager1 == null) {
EntityManager tmpEm = emf.createEntityManager(properties);
entityManager = new ExtendedEntityManager(unitName, tmpEm);
entityManager1 = new ReferenceCountedEntityManager((ExtendedEntityManager)entityManager);
if (JPA_LOGGER.isDebugEnabled())
JPA_LOGGER.debugf("created new ExtendedEntityManager for unit name=%s", unitName);
} else {
entityManager1.increaseReferenceCount();
entityManager = entityManager1.getEntityManager();
if (JPA_LOGGER.isDebugEnabled())
JPA_LOGGER.debugf("inherited existing ExtendedEntityManager from SFSB invocation stack, unit name=%s, " +
"%d beans sharing ExtendedEntityManager", unitName, entityManager1.getReferenceCount());
}
// register the EntityManager on TL so that SFSBCreateInterceptor will see it.
// this is important for creating a new XPC or inheriting existing XPC from SFSBCallStack
CreatedEntityManagers.registerPersistenceContext(entityManager1);