MTCoster
MTCoster

Reputation: 6145

Deploying Hibernate app to Wildfly 10 - org.dom4j.DocumentFactory ClassCastException

UPDATE: After destroying the WildFly instance and reconfiguring from scratch, the error has mysteriously resolved itself into a org.hibernate.MappingException for repeated columns. Now that I actually know what the problem is, I can get to work fixing it.


I'm currently evaluating JPA backed by Hibernate in WildFly 10. However, on attempting to deploy my test war (built by gradle) a seemingly irrelevant error is produced. Here are the lines from the console log:

11:11:06,200 ERROR [org.jboss.as.controller.management-operation] (management task-8) WFLYCTL0013: Operation ("add") failed - address: ([("deployment" => "TestWar.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"TestWar.war#com.myapp.testwar.jpa\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"TestWar.war#com.myapp.testwar.jpa\": java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory"}}

From my build.gradle:

group 'com.myapp'
name 'TestWar'
version '0.0.0-dev'

apply plugin: 'java'
apply plugin: 'war'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

configurations {
    provided
}

sourceSets {
    main {
        compileClasspath += configurations.provided
    }
}

dependencies {
    provided group: 'dom4j', name: 'dom4j', version: '1.6.1'
    provided group: 'javax.enterprise', name: 'cdi-api', version: '1.2'
    provided group: 'javax.inject', name: 'javax.inject', version: '1'
    provided group: 'org.hibernate', name: 'hibernate-core', version: '5.0.7.Final'
    provided group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.0.7.Final'
    provided group: 'org.hibernate', name: 'hibernate-envers', version: '5.0.7.Final'
    provided group: 'org.hibernate', name: 'hibernate-java8', version: '5.0.7.Final'
    provided group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.0.Final'
    provided group: 'org.jboss.spec.javax.annotation', name: 'jboss-annotations-api_1.2_spec', version: '1.0.0.Final'
    provided group: 'org.jboss.spec.javax.ejb', name: 'jboss-ejb-api_3.2_spec', version: '1.0.0.Final'
    provided group: 'org.jboss.spec.javax.sql', name: 'jboss-javax-sql-api_7.0_spec', version: '2.0.0.Final'
    provided group: 'org.jboss.spec.javax.ws.rs', name: 'jboss-jaxrs-api_2.0_spec', version: '1.0.0.Final'
    provided group: 'org.postgresql', name: 'postgresql', version: '9.4.1209'
}

I have tried the following solutions from similar posts on SO:

As well as these from other sources:

 

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
  <deployment>
    <dependencies>
      <module name="org.dom4j"/>
    </dependencies>
    <local-last value="true"/>
  </deployment>
</jboss-deployment-structure>

Does anyone have any further suggestions, or have I done something monumentally stupid?


Edit: Apparently this error can be caused by any datasource configuration issues (see here). For reference, the connection tests for my datasource via the admin console are successful, and the connection details are all correct as far as I'm aware.

Upvotes: 1

Views: 1137

Answers (1)

K.Nicholas
K.Nicholas

Reputation: 11551

This error happens (at the moment) because you included EntityManager in your dependency list. Remove that. You shouldn't need it for normal operation.

See this Hibernate Jira on the issue: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

Upvotes: 1

Related Questions