title: Entities not being detected when using packaged Hibernate JPA persistence provider
body: <p>Im deploying my web application on a local wildfly-11.0.0.Final
     server.
   Wildfly however provides its own hibernate and jpa modules which I
     dont want to use. I want to use the jpa jars packaged with my
     application.</p>
  
  <p>As described in
     <a href="https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-PackagingtheHibernateJPApersistenceproviderwithyourapplication" rel="nofollow noreferrer">https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-PackagingtheHibernateJPApersistenceproviderwithyourapplication</a>
     I added the line </p>
  
  <p><code>&lt;property name="jboss.as.jpa.providerModule" value="application"/&gt;</code> </p>
  
  <p>to my persistence.xml</p>
  
  <p>Now however my entites (Annotated with @Entity) are not being detected anymore and I have to explicitly name them in my persistence.xml like </p>
  
  <p><code>&lt;class&gt;com.mycompany.mywebapp.Actor&lt;/class&gt;</code></p>
  
  <p>Is there any way to fix this?</p>
  
  <p>I tried </p>
  
  <p><code>&lt;jar-file&gt;&lt;/jar-file&gt;</code></p>
  
  <p>and</p>
  
  <p><code>&lt;property name="hibernate.archive.autodetection" value="class, hbm"/&gt;</code></p>
  
  <p>without success.</p>
  
  <p>My persistence.xml looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &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="com.mycompany_mywebapp_war_1.0PU" transaction-type="JTA"&gt;
      &lt;jta-data-source&gt;java:/jboss/sakila&lt;/jta-data-source&gt;
      &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
      &lt;properties&gt;
        &lt;property name="jboss.as.jpa.providerModule" value="application"/&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Edit:</p>
  
  <p>Im using hibernate 5.3.7.Final which implements jpa 2.2.</p>
  
  <p>My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.</p>
  
  <p>Edit 2:</p>
  
  <p>I noticed that even though the hibernate version is now 5.3.7.Final the jpa provided by wildfly (specification version 2.1) is still being used which may be causing this issue.</p>
  
  <p>I tried disabling the wildfly modules in a jboss-deployment-structure.xml:</p>
  
  
  
  <pre><code>&lt;jboss-deployment-structure&gt;
      &lt;deployment&gt;
          &lt;exclusions&gt;
              &lt;module name="org.hibernate" /&gt;
              &lt;module name="javax.persistence.api" /&gt;
          &lt;/exclusions&gt;
      &lt;/deployment&gt;
  &lt;/jboss-deployment-structure&gt;
  </code></pre>
  
  <p>However now im facing following error:</p>
  
  <pre><code>Cannot upload deployment: {"WFLYCTL0080: Failed services" =&gt; {"jboss.deployment.unit.\"webapp-1.0.war\".FIRST_MODULE_USE" =&gt; "WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment \"webapp-1.0.war\" Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYJPA0019: Could not deploy application packaged persistence provider 'org.hibernate.jpa.HibernatePersistenceProvider' Caused by: java.lang.ClassCastException: class org.hibernate.jpa.HibernatePersistenceProvider"}}
  </code></pre>
  
  <p>Edit 3:</p>
  
  <p>To test whether this is the cause for my initial problem I manually replaced the jpa jar. Unfortunately this doesnt solve my problem.</p>
  
  <p>Anyway I would like to know how I can fix the issue of my packaged jpa jar not being used and how to make my entities be automatically detected again. Any hints?</p>