docs: private EntityManager getEntityManager(KieRuntimeEvent event) {
          
          Environment env = event.getKieRuntime().getEnvironment();
          
          /**
           * It's important to set the sharedEM flag with _every_ operation
           * otherwise, there are situations where:
           * 1. it can be set to "true"
           * 2. something can happen
           * 3. the "true" value can no longer apply 
           * (I've seen this in debugging logs.. )
           */
          sharedEM = false;
          if( emf != null ) { 
             return emf.createEntityManager();
          } else if (env != null) {
              EntityManagerFactory emf = (EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY);
              
              // first check active transaction if it contains entity manager
              EntityManager em = getEntityManagerFromTransaction(env);
  
              if (em != null && em.isOpen() && em.getEntityManagerFactory().equals(emf)) {
                  sharedEM = true;
                  return em;
              }
              // next check the environment itself
              em = (EntityManager) env.get(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER);
          	if (em != null) {
          		sharedEM = true;
          		return em;
          	}
              // lastly use entity manager factory
              if (emf != null) {
                  return emf.createEntityManager();
              }
          } 
          throw new RuntimeException("Could not find or create a new EntityManager!");
      }