Seeing ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory after applying JBoss EAP 7.1 CP6
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7.1 CP6
Issue
- We are seeing this exception after applying JBoss EAP 7.1 CP6 , out application is packaging dom4j.jar and the application has a JPA persistence unit in it.
Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
at org.dom4j.DocumentFactory.getInstance(DocumentFactory.java:92)
at org.hibernate.internal.util.xml.XMLHelper$1.doWork(XMLHelper.java:33)
at org.hibernate.internal.util.xml.XMLHelper$1.doWork(XMLHelper.java:27)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.workWithClassLoader(ClassLoaderServiceImpl.java:358)
at org.hibernate.internal.util.xml.XMLHelper.<init>(XMLHelper.java:26)
at org.hibernate.envers.boot.internal.EnversServiceImpl.initialize(EnversServiceImpl.java:115)
at org.hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl.produceAdditionalMappings(AdditionalJaxbMappingProducerImpl.java:99)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:288)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:848)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:875)
at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:167)
... 7 more
Resolution
For EAP 7.1 CP6 apply the patch This content is not included.HHH-13285 - ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory after dom4j update
For EAP 7.1 update RPMs to get the fix.
The issue is fixed in JBoss EAP 7.2+
If the dom4j.jar is not being used by the application (as it is a JPA / Hibernate dependency and Hibernate uses the dom4j included in JBoss EAP), then you can just remove the dom4j.jar from the application since it is not being used.
Or you can add a jboss-deployment-structure.xml to your ear's META-INF such as this , it would workaround the issue, or removing the dom4j.jar would resolve it as well.
<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="org.dom4j" export="true"/>
</dependencies>
</jboss-deployment-structure>
If these workarounds are not acceptable and you cannot move to EAP 7.2 , open a support case and discuss with support about another fix.
Root Cause
Content from issues.jboss.org is not included.Content from issues.jboss.org is not included.https://issues.jboss.org/browse/JBEAP-16443
Content from issues.jboss.org is not included.Content from issues.jboss.org is not included.https://issues.jboss.org/browse/JBEAP-16442
Content from hibernate.atlassian.net is not included.Content from hibernate.atlassian.net is not included.https://hibernate.atlassian.net/browse/HHH-13285
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.