picketlink/src/main/java/org/wildfly/extension/picketlink/idm/jpa/transaction/TransactionalEntityManagerHelper.java
public  void putEntityManagerInTransactionRegistry(String scopedPuName, EntityManager entityManager) {
        try {
            Transaction transaction = this.transactionManager.getTransaction();

            transaction.registerSynchronization(new TransactionalEntityManagerSynchronization(entityManager));

            this.transactionSynchronizationRegistry.putResource(scopedPuName, entityManager);
        } catch (Exception e) {
            throw PicketLinkLogger.ROOT_LOGGER.idmJpaFailedCreateTransactionEntityManager(e);
        }
    }
public  void putEntityManagerInTransactionRegistry(String scopedPuName, EntityManager entityManager) {
        try {
            Transaction transaction = this.transactionManager.getTransaction();

            transaction.registerSynchronization(new TransactionalEntityManagerSynchronization(entityManager));

            this.transactionSynchronizationRegistry.putResource(scopedPuName, entityManager);
        } catch (Exception e) {
            throw PicketLinkLogger.ROOT_LOGGER.idmJpaFailedCreateTransactionEntityManager(e);
        }
    }
Save the specified EntityManager in the local threads active transaction.  The TransactionSynchronizationRegistry
will clear the reference to the EntityManager when the transaction completes.

@param scopedPuName
@param entityManager