code: private EntityManager getEntityManager() {
  
          EntityManager em;
  
          if (TxUtils.isActive(transactionManager)) {
  
              em = (EntityManager) transactionSynchronizationRegistry.getResource(unitName);
  
              if (em == null) {
  
                  em = createEntityManager();
  
                  transactionSynchronizationRegistry.registerInterposedSynchronization(new TxSynchronization(em));
                  transactionSynchronizationRegistry.putResource(unitName, em);
              } else {
  
                  validateCompatibleSyncTypes(em);
              }
          } else {
  
              em = nonTxEmHolder.getEntityManager();
  
              if (em == null) {
  
                  em = createEntityManager();
  
                  nonTxEmHolder.setEntityManager(em);
              }
          }
  
          return em;
      }
docs: // Private logic methods