picketlink/src/main/java/org/wildfly/extension/picketlink/idm/service/JPAIdentityStoreService.java
private EntityManager getOrCreateTransactionalEntityManager(TransactionManager transactionManager) {
        try {
            if (transactionManager.getStatus() == Status.STATUS_ACTIVE) {
                EntityManager entityManager = this.transactionalEntityManagerHelper.getTransactionScopedEntityManager(getPersistenceUnitName());

                if (entityManager == null) {
                    entityManager = createEntityManager(transactionManager);
                    this.transactionalEntityManagerHelper.putEntityManagerInTransactionRegistry(getPersistenceUnitName(), entityManager);
                }

                return entityManager;
            }
        } catch (Exception e) {
            throw ROOT_LOGGER.idmJpaFailedCreateTransactionEntityManager(e);
        }

        return null;
    }
private EntityManager getOrCreateTransactionalEntityManager(TransactionManager transactionManager) {
        try {
            if (transactionManager.getStatus() == Status.STATUS_ACTIVE) {
                EntityManager entityManager = this.transactionalEntityManagerHelper.getTransactionScopedEntityManager(getPersistenceUnitName());

                if (entityManager == null) {
                    entityManager = createEntityManager(transactionManager);
                    this.transactionalEntityManagerHelper.putEntityManagerInTransactionRegistry(getPersistenceUnitName(), entityManager);
                }

                return entityManager;
            }
        } catch (Exception e) {
            throw ROOT_LOGGER.idmJpaFailedCreateTransactionEntityManager(e);
        }

        return null;
    }
<p>Returns an {@link javax.persistence.EntityManager} associated with the actual {@link javax.transaction.Transaction}, if present.</p>

<p>If {@link javax.transaction.Transaction} is {@link Status#STATUS_ACTIVE}, this method tries to return an entity manager
already associated with it. If there is no entity manager a new one is created.</p>

<p>This method is specially useful when IDM is being called from an EJB or any other component that have already started
a transaction. In this case, the client code is responsible to commit or rollback the transaction accordingly.</p>

<p>The returned {@link EntityManager} is always closed before the transaction completes.</p>

@param transactionManager The transaction manager.

@return The {@link EntityManager} associated with the actual transaction or null if there is no active transactions.