1

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.

As described in https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-PackagingtheHibernateJPApersistenceproviderwithyourapplication I added the line

<property name="jboss.as.jpa.providerModule" value="application"/>

to my persistence.xml

Now however my entites (Annotated with @Entity) are not being detected anymore and I have to explicitly name them in my persistence.xml like

<class>com.mycompany.mywebapp.Actor</class>

Is there any way to fix this?

I tried

<jar-file></jar-file>

and

<property name="hibernate.archive.autodetection" value="class, hbm"/>

without success.

My persistence.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<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">
  <persistence-unit name="com.mycompany_mywebapp_war_1.0PU" transaction-type="JTA">
    <jta-data-source>java:/jboss/sakila</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="jboss.as.jpa.providerModule" value="application"/>
    </properties>
  </persistence-unit>
</persistence>

Edit:

Im using hibernate 5.3.7.Final which implements jpa 2.2.

My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.

Edit 2:

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.

I tried disabling the wildfly modules in a jboss-deployment-structure.xml:

<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.hibernate" />
            <module name="javax.persistence.api" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

However now im facing following error:

Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"webapp-1.0.war\".FIRST_MODULE_USE" => "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"}}

Edit 3:

To test whether this is the cause for my initial problem I manually replaced the jpa jar. Unfortunately this doesnt solve my problem.

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?

  • The `persistence.xml` and the entity classes need to be in the same file tree. Meaning the either in the root war file, or in the same jar file. If you can't restructure it like that, then you need to list the entity classes in the xml. – coladict Jan 02 '19 at 06:04
  • I dont think thats the issue. My classes are in mywebapp-1.0.war\WEB-INF\classes\com\mycompany\mywebapp\ and my persistence.xml in mywebapp-1.0.war\WEB-INF\classes\META-INF\ My entites have been detected correctly when not using the packaged jpa persistence provider. I tried having my entities in a seperate jar and use lib/data.jar in my persistence.xml without succes. – User5458751 Jan 02 '19 at 06:38
  • Does the version of Hibernate that you want to use implement the same version of JPA as that provided by WildFly 11? – Steve C Jan 02 '19 at 08:46
  • No. Im using hibernate 5.3.7.Final which implements jpa 2.2. My wildfly server provides hibernate 5.1.10.Final with jpa 2.1. – User5458751 Jan 02 '19 at 09:20
  • With the edit that shows the error we see the problem. When you have a ClassCastException with a class not being able to cast to itself, then you have a classloader problem. Two classloaders have loaded the same class from two different jars. One loaded it from Wildfly, the other from Hibernate. You need to remove or disable the embedded version. [This wiki entry](https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-ReplacingthecurrentHibernate5.xjarswithanewerversion) should help. – coladict Jan 03 '19 at 21:21
  • Excluding the hibernate and jpa modules in my jboss-deployment-structure.xml is what led to this error. The wiki entry says to replace the wildfly jars but I dont want to do this since this will affect all of my applications. – User5458751 Jan 05 '19 at 19:24

0 Answers0