Using Custom JPA / Hibernate Provider in Wildfly 8.1 Warfile
JPA / Hibernate provider is included in my application, but I am having problems deploying it in wildfly 8.1. Namely, I am using an OSS project called OpenXava that ships with its own version of Hibernate. I previously had success with JBoss 5.1, but WildFly 8.1 gives me an error when deploying.
I asked the lead developer of OpenXava and he says this is most likely a problem with configuring WildFly to use the JPA provider bundled with a war file. I looked through the documentation for WF and found the jboss.as.jpa.providerModule parameter. I tried to install this app as well as hibernate3-bundled and none of them work. I've also tried excluding modules via jboss-deployment-structure.xml. This generated several different errors, but didn't seem to be successful.
Does anyone know what's going on?
My jboss-deployment-structure.xml looks like this:
<deployment>
<exclusions>
<module name="org.dom4j" />
<module name="org.hibernate"/>
<module name="javax.persistence.api"/>
</exclusions>
</deployment>
My persistence.xml looks like this:
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">
<!-- Tomcat + Hypersonic -->
<persistence-unit name="default">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.openxava.session.GalleryImage</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="jboss.as.jpa.providerModule" value="application" />
</properties>
</persistence-unit>
<!-- JUnit Hypersonic -->
<persistence-unit name="junit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost:1666"/>
</properties>
When I deploy the application, it returns the following error (I am using the MySchool.war sample application provided in OpenXava):
13: 15: 17.563 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start jboss.deployment.unit service. "MySchool.war" .FIRST_MODULE_USE: org. jboss.msc.service.StartException on jboss.deployment.unit service. "MySchool.war" .FIRST_MODULE_USE: JBAS018733: Failed to process the FIRST_MODULE_USE phase of the "MySchool.war" deployment
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: Unable to deploy package provider with packages installed "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 stream) JBAS014613: Operation failed ("deploy"): ([("deploy" => "MySchool. War")]) - error description: {"JBAS014671: Failed services" => {"jboss.deployment.unit. \" MySchool.war \ ". FIRST_MODULE_USE" => "org.jboss.msc.service.StartException in jboss.deployment.unit service . \ "MySchool.war \". FIRST_MODULE_USE: JBAS018733: Failed to process the FIRST_MODULE_USE phase of deployment \ "MySchool.war \"
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"}}
source to share
According to Winldfly 8 documentation , you need to change your continuity provider:
<provider>org.hibernate.ejb.HibernatePersistence</provider>
in
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
source to share
I believe the reason for this question is because you missed this dependency
<dependency>
<groupId>org.jipijapa</groupId>
<artifactId>jipijapa-hibernate4-3</artifactId>
<version>1.0.1.Final</version>
</dependency>
After adding dependencies I was able to use Hibernate 4.3.5.Final in Wildfly8.2.Final.
source to share