title: EntityManager is null when injected in WildFly 10 EJB
body: <p>I have been working on moving our application from JBoss AS 6 to Wildfly 10. The main problem I have been stuck on is that the EntityManager does not get injected into the EJB. I have been researching this for a while and trying everything I find but nothing helps.</p>
  
  <p>I don't have a simple application to recreate the problem yet but here are some details and snippets of code.</p>
  
  <p>We are deploying using a SAR file. This is a Spring framework application. Our second level cache is turned off for now. That's another problem I need to tackle.</p>
  
  <p>persistence.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                  http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
          version="1.0"&gt;
    &lt;persistence-unit name="IpsDb" transaction-type="JTA"&gt;
      &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
      &lt;jta-data-source&gt;java:jboss/datasources/HarmonyServerDS&lt;/jta-data-source&gt;
      &lt;jar-file&gt;../harmonyserver-model.jar&lt;/jar-file&gt;
      &lt;properties&gt;
        &lt;!-- pessimistic lock timeout in milliseconds (Integer or String), this is a hint used by Hibernate but requires support by your underlying database. --&gt;
        &lt;property name="javax.persistence.lock.timeout" value="15000"/&gt;
        &lt;!-- query timeout in milliseconds (Integer or String), this is a hint used by Hibernate but requires support by your underlying database --&gt; 
        &lt;property name="javax.persistence.query.timeout" value="15000"/&gt;
        &lt;property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" /&gt;
        &lt;property name="hibernate.cache.use_query_cache" value="false"/&gt;
        &lt;property name="hibernate.cache.use_second_level_cache" value="false"/&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Beginning of the datasource from standalone-full.xml:</p>
  
  <pre><code>&lt;datasource jta="true" jndi-name="java:jboss/datasources/HarmonyServerDS" pool-name="HarmonyServerDS" enabled="true" use-java-context="true" spy="false" use-ccm="true" connectable="false"&gt;
  </code></pre>
  
  <p>From the EJB class (These are the important parts but not all of the code from the class):</p>
  
  <pre><code>@Stateless
  @Clustered
  public class DataModificationBean implements DataModificationLocal {
  
      @PersistenceUnit(unitName="IpsDb")
      private EntityManagerFactory entityMgrFactory;
  
      @PersistenceContext(unitName="IpsDb")
      private EntityManager entityMgr;
  
      @Override
      @Transactional(propagation=Propagation.REQUIRES_NEW)
      @InterruptOnTransactionTimeout(value=true)
      public DataModificationResponse handleModification(DataModification mod, ModificationHandler handler, AdaptationContext adaptation, boolean bulk_lock)
      {
          try {
              // Handler's data update monitor for delta changes. 
              DataUpdateMonitor updateMonitor = null;
  
              // Pre-process the request and gather up the dataContext for processing.
              logger.info("DataModificationBean EntityMgr=" + (entityMgr == null ? "null" : entityMgr.toString()));
              logger.info("DataModificationBean EntityMgrFactory=" + (entityMgrFactory == null ? "null" : entityMgrFactory.toString()));
              handler.preProcess(this, entityMgr);
  ...
  </code></pre>
  
  <p>The logging at the bottom of that snippet shows that the entityMgr and entityMgrFactory are null. </p>
  
  <p>Is there something else I'm missing? Or anything else I could show that would be helpful?</p>