title: Using custom JPA/Hibernate provider in a war file in Wildfly 8.1
body: <p>The JPA/Hibernate provider is bundled within my application, but I'm having trouble when deploying it to wildfly 8.1.  Namely I'm using an OSS project called OpenXava, which is bundled with its own Hibernate version.  I've previously had success with this on JBoss 5.1, but WildFly 8.1 gives me an error when I deploy it.</p>
  <p>I've asked the lead developer of OpenXava, and he says it's most likely a problem with configuring WildFly to use a the JPA provider bundled in the war file.  I've looked through the documentation for WF, and found the jboss.as.jpa.providerModule setting.  I've tried setting this to application, and to hibernate3-bundled, and neither works.  I've also tried excluding modules via jboss-deployment-structure.xml.  This created some different errors, but didn't seem to be successful.</p>
  <p>Does anyone have any clue what's going on?</p>
  <p>My jboss-deployment-structure.xml looks like:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; 
  &lt;jboss-deployment-structure&gt; 
        &lt;deployment&gt; 
           &lt;exclusions&gt; 
             &lt;module name=&quot;org.dom4j&quot; /&gt; 
             &lt;module name=&quot;org.hibernate&quot;/&gt;
             &lt;module name=&quot;javax.persistence.api&quot;/&gt;
           &lt;/exclusions&gt; 
        &lt;/deployment&gt; 
  &lt;/jboss-deployment-structure&gt;
  </code></pre>
  <p>My persistence.xml looks like:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot;
               xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
               xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot;
               version=&quot;1.0&quot;&gt;
              
      &lt;!-- Tomcat + Hypersonic --&gt;
      &lt;persistence-unit name=&quot;default&quot;&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;class&gt;org.openxava.session.GalleryImage&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name=&quot;hibernate.dialect&quot; value=&quot;org.hibernate.dialect.HSQLDialect&quot;/&gt;
          &lt;property name=&quot;jboss.as.jpa.providerModule&quot; value=&quot;application&quot; /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;   
  
      &lt;!-- JUnit Hypersonic --&gt;
      &lt;persistence-unit name=&quot;junit&quot;&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;properties&gt;
              &lt;property name=&quot;hibernate.connection.driver_class&quot; value=&quot;org.hsqldb.jdbcDriver&quot;/&gt;
              &lt;property name=&quot;hibernate.dialect&quot; value=&quot;org.hibernate.dialect.HSQLDialect&quot;/&gt;
              &lt;property name=&quot;hibernate.connection.url&quot; value=&quot;jdbc:hsqldb:hsql://localhost:1666&quot;/&gt;
          &lt;/properties&gt;
  </code></pre>
  <p>When I deploy the application, it returns the following error (I'm using the example application MySchool.war provided in OpenXava):</p>
  <pre><code>13:15:17,563 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit.&quot;MySchool.war&quot;.FIRST_MODULE_USE: org.jboss.msc.service.StartException in service jboss.deployment.unit.&quot;MySchool.war&quot;.FIRST_MODULE_USE: JBAS018733: Failed to process phase FIRST_MODULE_USE of deployment &quot;MySchool.war&quot;
      at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_05]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_05]
      at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_05]
  Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011426: Could not deploy application packaged persistence provider 'org.hibernate.ejb.HibernatePersistence'
      at org.jboss.as.jpa.processor.PersistenceProviderHandler.deploy(PersistenceProviderHandler.java:81)
      at org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor.deploy(PersistenceBeginInstallProcessor.java:49)
      at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
      ... 5 more
  Caused by: java.lang.ClassCastException: class org.hibernate.ejb.HibernatePersistence
      at java.lang.Class.asSubclass(Class.java:3293) [rt.jar:1.8.0_05]
      at org.jboss.as.jpa.processor.PersistenceProviderHandler.deploy(PersistenceProviderHandler.java:74)
      ... 7 more
   
  13:15:17,587 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation (&quot;deploy&quot;) failed - address: ([(&quot;deployment&quot; =&gt; &quot;MySchool.war&quot;)]) - failure description: {&quot;JBAS014671: Failed services&quot; =&gt; {&quot;jboss.deployment.unit.\&quot;MySchool.war\&quot;.FIRST_MODULE_USE&quot; =&gt; &quot;org.jboss.msc.service.StartException in service jboss.deployment.unit.\&quot;MySchool.war\&quot;.FIRST_MODULE_USE: JBAS018733: Failed to process phase FIRST_MODULE_USE of deployment \&quot;MySchool.war\&quot;
      Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011426: Could not deploy application packaged persistence provider 'org.hibernate.ejb.HibernatePersistence'
      Caused by: java.lang.ClassCastException: class org.hibernate.ejb.HibernatePersistence&quot;}}
  </code></pre>