/**
   * Associate the extended persistence context with the current JTA transaction (if one is found)
   *
   * <p>this method is private to the JPA subsystem
   */
  public void internalAssociateWithJtaTx() {
    isInTx = TransactionUtil.isInTx();

    // ensure that a different XPC (with same name) is not already present in the TX
    if (isInTx) {

      // 7.6.3.1 throw EJBException if a different persistence context is already joined to the
      // transaction (with the same puScopedName).
      EntityManager existing = TransactionUtil.getTransactionScopedEntityManager(puScopedName);
      if (existing != null && existing != this) {
        // should be enough to test if not the same object
        throw JpaLogger.ROOT_LOGGER.cannotUseExtendedPersistenceTransaction(
            puScopedName, existing, this);
      } else if (existing == null) {

        if (SynchronizationType.SYNCHRONIZED.equals(synchronizationType)) {
          // JPA 7.9.1 join the transaction if not already done for
          // SynchronizationType.SYNCHRONIZED.
          underlyingEntityManager.joinTransaction();
        }
        // associate the entity manager with the current transaction
        TransactionUtil.putEntityManagerInTransactionRegistry(puScopedName, this);
      }
    }
  }