0 Replies Latest reply on May 15, 2019 6:42 PM by david.tierens

    Use other Hibernate version on Wildfly 16

    david.tierens

      We want to use another Hibernate version (5.2.18.Final, JPA 2.1) on our application server (Wildfly V16.0) but we are getting following exception :

      {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"david-app.ear#examplePersistenceUnit\".__FIRST_PHASE__" => "java.lang.ClassCastException: class 
      org
      .hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl cannot be cast to class org.hibernate.boot.model.naming.ImplicitNamingStrategy
      (org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl is in unnamed module of loader 'org.hibernate:5.2.18.Final@5.2.18.Final' @155c18e0; org.hibernate.boot.model.naming.ImplicitNamingStrategy
      is in unnamed module of loader 'org.hibernate@5.3.9.Final' @102121eb) Caused by: java.lang.ClassCastException: class org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl cannot be cast to class
      org
      .hibernate.boot.model.naming.ImplicitNamingStrategy (org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl is in unnamed module of loader 'org.hibernate:5.2.18.Final@5.2.18.Final'
      @155c18e0; org.hibernate.boot.model.naming.ImplicitNamingStrategy is in unnamed module of loader 'org.hibernate@5.3.9.Final' @102121eb)"}}

      It seems that it's trying to load 2 hibernate versions at the same time but this should be avoided with following configurations:

      jboss-deployment-structure.xml (resources/META-INF) :

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-deployment-structure>
      <deployment>
        
      <exclusions>
        
      <module name="org.hibernate" slot="main"/>
        
      </exclusions>
        
      <dependencies>
        
      <module name="org.hibernate" slot="5.2.18.Final"/>
        
      </dependencies>
      </deployment>

      </jboss-deployment-structure>

       

      persistence.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence 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"
        version
      ="2.1">
        
      <persistence-unit name="examplePersistenceUnit" transaction-type="JTA">
        
      <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        
      <jta-data-source>jdbc/CoreXADataSource</jta-data-source>
        
      <properties>
        
      <property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2.18.Final"/>
        
      <property name="hibernate.show_sql" value="false"/>
        
      <property name="hibernate.order_inserts" value="true"/>
        
      <property name="hibernate.jdbc.wrap_result_sets" value="true"/>
        
      </properties>
      </persistence-unit>

      Hibernate module.xml (5.2.18.Final slot) in Wildfly :

      <?xml version="1.0" encoding="UTF-8"?>
      <module name="org.hibernate:5.2.18.Final" xmlns="urn:jboss:module:1.8">
      <resources>
        
      <resource-root path="hibernate-core-5.2.18.Final.jar"/>
        
      <resource-root path="hibernate-entitymanager-5.2.18.Final.jar"/>
        
      <resource-root path="hibernate-java8-5.2.18.Final.jar"/>
      </resources>

      <dependencies>
        
      <module name="com.fasterxml.classmate"/>
        
      <module name="javax.api"/>
        
      <module name="javax.annotation.api"/>
        
      <module name="javax.enterprise.api"/>
        
      <module name="javax.persistence.api"/>
        
      <module name="javax.transaction.api"/>
        
      <module name="javax.validation.api"/>
        
      <module name="javax.xml.bind.api"/>
        
      <module name="org.antlr"/>
        
      <module name="org.dom4j"/>
        
      <module name="org.javassist" export="true"/>
        
      <module name="org.jboss.as.jpa.spi"/>
        
      <module name="org.jboss.jandex"/>
        
      <module name="org.jboss.logging"/>
        
      <module name="org.jboss.vfs"/>
        
      <module name="org.hibernate.commons-annotations"/>
        
      <module name="org.hibernate.jipijapa-hibernate5" services="import"/>
        
      <module name="org.infinispan.hibernate-cache" services="import" optional="true"/>
      </dependencies>

      Anyone has an idea why Wildfly still tries to load his default Hibernate version 5.3.9 while deploying an EAR file ?

      Stackoverflow thread: java - Hibernate ClassCastException ImplicitNamingStrategyJpaCompliantImpl - Stack Overflow