1

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.

9
  • You have a Problem with classloader
    – Jens
    Aug 2, 2016 at 11:46
  • @Jens I'm not doing any classloading myself, although I am aware that WildFly is during deployment. Could you expand on where the problem might be originating?
    – MTCoster
    Aug 2, 2016 at 11:47
  • jboss has more than one classloader. So it Looks like you have dom4j jar multiple times on different classloaders
    – Jens
    Aug 2, 2016 at 11:50
  • @Jens Okay, but where is this second instance coming from? This is a fresh instance of WildFly. The only actions I've taken are to install the PostgreSQL JDBC driver as a deployed jar; configure my datasource, and attempt to deploy my test war. It doesn't seem right that WildFly would ship with multiple instances of the same library
    – MTCoster
    Aug 2, 2016 at 11:52
  • I do not know. Understanding classloading is very complicated
    – Jens
    Aug 2, 2016 at 11:56

1 Answer 1

1

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

2
  • Since the error has now resolved itself, I can't test this now. If it comes back, I'll give it a try though. But why does this make a difference when the dependencies are all listed as provided? None of them are actually copied to the war
    – MTCoster
    Aug 2, 2016 at 13:23
  • The EntityManger jar has the old org.dom4j jar in it, so even though you may be getting it from wildfly, it still can't load.
    – K.Nicholas
    Aug 2, 2016 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.