title: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001456 : Argument resolvedBean must not be null
body: <p>This question is purely based on <a href="https://stackoverflow.com/q/33891368/1391249">this question</a>.</p>
  
  <hr>
  
  <p>I have created a sendbox Java EE application in WildFly 10.0.0 final using Hibernate 5.1.0 final / Weld 2.3.2 final. The project contains nothing other than a single entity class, an entity listener and one plain blank local stateless session bean - no complexity, no extra dependency at all.</p>
  
  <p>It is a standard NetBeans project built and deployed by Apache Ant. Thus, it does not use Apache Maven.</p>
  
  <p>The entity listener is registered in <code>/META-INF/orm.xml</code>.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;entity-mappings version="2.1"
                   xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd"&gt;
  
      &lt;entity class="entity.Discount"&gt;
          &lt;entity-listeners&gt;
              &lt;entity-listener class="entity.listener.DiscountListener"/&gt;
          &lt;/entity-listeners&gt;
      &lt;/entity&gt;
  &lt;/entity-mappings&gt;
  </code></pre>
  
  <p>The <code>persistence.xml</code> file.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;persistence version="2.1"
               xmlns="http://xmlns.jcp.org/xml/ns/persistence"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
      &lt;persistence-unit name="Test-ejbPU" transaction-type="JTA"&gt;
          &lt;jta-data-source&gt;java:jboss/datasources/datasource&lt;/jta-data-source&gt;
          &lt;mapping-file&gt;META-INF/orm.xml&lt;/mapping-file&gt;
  
          &lt;class&gt;entity.Discount&lt;/class&gt;
          &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>The local stateless session bean is left completely blank (contains nothing, not even a single line).</p>
  
  <pre><code>@Stateless
  public class TestBean implements TestService {
  
  }
  </code></pre>
  
  <p>The entity listener contains an injection point of the above stateless session bean (this is also not coded).</p>
  
  <pre><code>public class DiscountListener {
  
      @Inject
      private TestService service;
  
      @PostPersist
      public void postPersist() {
  
      }
  }
  </code></pre>
  
  <p>The deployment process terminates abruptly with the following exception.</p>
  
  <pre><code>20:17:54,656 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 116) MSC000001: Failed to start service jboss.persistenceunit."Test.ear/Test-ejb.jar#Test-ejbPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."Test.ear/Test-ejb.jar#Test-ejbPU": javax.persistence.PersistenceException: [PersistenceUnit: Test-ejbPU] Unable to build Hibernate SessionFactory
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
      at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
      at org.jboss.threads.JBossThread.run(JBossThread.java:320)
  Caused by: javax.persistence.PersistenceException: [PersistenceUnit: Test-ejbPU] Unable to build Hibernate SessionFactory
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:884)
      at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
      ... 7 more
  Caused by: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001456: Argument resolvedBean must not be null
      at org.jboss.weld.util.Preconditions.checkArgumentNotNull(Preconditions.java:40)
      at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:794)
      at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
      at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:378)
      at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:389)
      at org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:70)
      at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
      at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:72)
      at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121)
      at org.hibernate.jpa.event.internal.jpa.ListenerFactoryBeanManagerStandardImpl$ListenerImpl.&lt;init&gt;(ListenerFactoryBeanManagerStandardImpl.java:93)
      at org.hibernate.jpa.event.internal.jpa.ListenerFactoryBeanManagerStandardImpl$ListenerImpl.&lt;init&gt;(ListenerFactoryBeanManagerStandardImpl.java:82)
      at org.hibernate.jpa.event.internal.jpa.ListenerFactoryBeanManagerStandardImpl.buildListener(ListenerFactoryBeanManagerStandardImpl.java:68)
      at org.hibernate.jpa.event.internal.jpa.CallbackBuilderLegacyImpl.resolveCallbacks(CallbackBuilderLegacyImpl.java:170)
      at org.hibernate.jpa.event.internal.jpa.CallbackBuilderLegacyImpl.buildCallbacksForEntity(CallbackBuilderLegacyImpl.java:69)
      at org.hibernate.jpa.event.spi.JpaIntegrator.integrate(JpaIntegrator.java:134)
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:276)
      at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:881)
      ... 9 more
  
  20:17:54,671 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" =&gt; {"jboss.persistenceunit.\"Test.ear/Test-ejb.jar#Test-ejbPU\"" =&gt; "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"Test.ear/Test-ejb.jar#Test-ejbPU\": javax.persistence.PersistenceException: [PersistenceUnit: Test-ejbPU] Unable to build Hibernate SessionFactory
      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: Test-ejbPU] Unable to build Hibernate SessionFactory
      Caused by: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001456: Argument resolvedBean must not be null"}}
  </code></pre>
  
  <p>According to <a href="https://hibernate.atlassian.net/browse/HHH-8706" rel="nofollow noreferrer">this issue status</a>, this issue has however been fixed in Hibernate 5.1.0 final.</p>
  
  <hr>
  
  <p><strong>Additional :</strong></p>
  
  <p>The application succeeds, when a <code>true</code> value is given in,</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;
  </code></pre>
  
  <p>and the annotation approach is used to mark the entity listener avoiding the XML mapping in <code>orm.xml</code> i.e. when the <code>Discount</code> entity is decorated with <code>@EntityListeners(DiscountListener.class)</code>.</p>
  
  <p>Doing so is however disallowed in my environment, since I use a class library to bridge common functionalities across two modules namely the EJB module and the WAR module in which I have placed entity classes in the class library (as far as I am concerned, injection points in a class library do not work as it does not have a Java EE environment - it is not qualified and consequently, entity listeners along with <code>@EntityListeners(ListenerClass.class)</code> cannot be used therein).</p>
  
  <p>Obviously, entity classes would need to be added to both the places namely the EJB module and the class library, if that approach were to be adopted because the class library would also need entity classes to be present on its compile-time class-path. This will in turn result in <code>java.lang.ClassCastException: com.example.Entity cannot be cast to com.example.Entity</code>, since there are duplicate entity classes on the run-time class-path.</p>
  
  <p>&#9658; This nevertheless succeeds on GlassFish Server which does not complain about the duplication.</p>
  
  <p>Entity classes along with the JPA static metamodel have been placed in a class library and entity listener classes have been placed in the associated EJB module and registered in <code>/META-INF/orm.xml</code> (EJB module).</p>
  
  <hr>
  
  <p><strong>The approach mentioned throughout the question succeeds on GlassFish Server / EclipseLink. Therefore, I expect it to work on WildFly / Hibernate.</strong></p>
  
  <p>What may be the possible way to go about? It should function in anyway without breaking the Java EE contract - not necessarily the only way I have mentioned but keeping the class library intact is essential.</p>
  
  <p><sub>P.S. The project does not use Apache Maven which does not support a class library as far as I know.</sub></p>