14 Replies Latest reply on Mar 2, 2016 2:20 PM by chandra pawar

    Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

    Dean Schulze Newbie

      I've deploy RESTful web services in a .war file in JBoss AS 7.1. So far so good. Then I add a .jar file with JPA 2.0 Entities to that .war file.  JBoss throws the following Exception when the .war is deployed:

      org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

      This problem is posted numerous times all over the web and there are about half as many suggested solutions but none of them work.

      There is no dom4j.jar in my archive. My Hibernate 4.0 dependencies are all<scope>provided</scope>. None of the .jar files included in my .war file have any dom4j classes in them.

      Does anyone know what causes this with JBoss 7.1 and what the solution is?

        • 1. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
          Scott Marlow Master

          Can you show us the contents of your .war file?  Doing a "jar tf your.war" (with the corrected war file name) should give the file list.

          • 2. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
            Dean Schulze Newbie

            The problems started when I added the learn-entity-6.2.0-SNAPSHOT.jar file that contains the Entities.

             

            Here are the contents of the .war file.  The problematic .jar file contents are below

             

            $ jar tf service-mobile.war

            META-INF/

            META-INF/MANIFEST.MF

            WEB-INF/

            WEB-INF/classes/

            WEB-INF/classes/com/

            WEB-INF/classes/com/kf/

            WEB-INF/classes/com/kf/amplifire/

            WEB-INF/classes/com/kf/amplifire/mobile/

            WEB-INF/classes/com/kf/amplifire/mobile/svc/

            WEB-INF/classes/com/kf/amplifire/mobile/svc/account/

            WEB-INF/lib/

            WEB-INF/classes/com/kf/amplifire/mobile/svc/account/MobileRestService.class

            WEB-INF/classes/com/kf/amplifire/mobile/svc/account/MobileRestServiceMock.class

            WEB-INF/classes/log4j.properties

            WEB-INF/jboss-web.xml

            WEB-INF/lib/client-account-6.2.0-20120802.143330-10.jar

            WEB-INF/lib/client-learning-6.2.0-SNAPSHOT.jar

            WEB-INF/lib/client-registration-6.2.0-20120803.200617-5.jar

            WEB-INF/lib/common-mobile-6.2.0-SNAPSHOT.jar

            WEB-INF/lib/commons-codec-1.6.jar

            WEB-INF/lib/json-20090211.jar

            WEB-INF/lib/learn-entity-6.2.0-SNAPSHOT.jar

            WEB-INF/lib/log4j-1.2.16.jar

            WEB-INF/web.xml

             

            $ jar tf learn-entity-6.2.0-SNAPSHOT.jar

            META-INF/

            META-INF/MANIFEST.MF

            learn/

            learn/entity/

            learn/entity/Answer.class

            learn/entity/AnswerHistory.class

            learn/entity/Context.class

            learn/entity/ExternalRequest.class

            learn/entity/ExternalSession.class

            learn/entity/LearningUnitState.class

            learn/entity/LearningUnitStatePK.class

            learn/entity/package-info.class

            learn/entity/Patch.class

            learn/entity/Question.class

            learn/entity/QuestionHistory.class

            learn/entity/Session.class

            learn/entity/StateTransition.class

            learn/entity/StateTransitionPK.class

            learn/entity/Throttle.class

            META-INF/persistence.xml

            • 3. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
              Scott Marlow Master

              Can you show us the contents of the MANIFEST.MF files?  Easiest way is to copy the service-mobile.war somewhere and do a "jar xf service-mobile.war" to extract the contents.  Get the contents of the service-mobile.war MANIFEST.MF and then do a "jar xf learn-entity-6.2.0-SNAPSHOT.jar" and get the contents of the META-INF/MANIFEST.MF from there.

              • 4. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
                Dean Schulze Newbie

                Here's the manifest.mf from the learn-entity-6.2.0-SNAPSHOT.jar:

                 

                Manifest-Version: 1.0

                Archiver-Version: Plexus Archiver

                Created-By: Apache Maven

                Built-By: dschulze

                Build-Jdk: 1.6.0_33

                 

                Here's from the .war file:

                 

                Manifest-Version: 1.0

                Implementation-Vendor: KFI

                Implementation-Title: service-mobile

                Implementation-Version:

                Implementation-Vendor-Id: com.kfi

                Dependencies: org.dom4j export

                Built-By: dschulze

                Build-Jdk: 1.6.0_33

                Created-By: Apache Maven 3.0.4

                Archiver-Version: Plexus Archiver

                 

                 

                Note that I added the "Dependencies: org.dom4j export" because it is one of the many suggested solutions to this problem on the web.  It made no difference, however.

                • 5. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
                  Scott Marlow Master

                  Show us the full exception call stack, it should still be in the as7/standalone/log/server.log file.  I want to verify that the exception is occuring on the application deployment classpath and not on some static (AS7) modules classpath.

                  • 6. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
                    Dean Schulze Newbie

                    15:24:23,049 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-3) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory

                    15:24:23,050 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-3) HHH000397: Using ASTQueryTranslatorFactory

                    15:24:23,068 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.persistenceunit."service-mobile.war#kfv6DS_learn": org.jboss.msc.service.StartException in service jboss.persistenceunit."service-mobile.war#kfv6DS_learn": Failed to start service

                              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

                              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_32]

                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_32]

                              at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_32]

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

                              at org.dom4j.DocumentFactory.getInstance(DocumentFactory.java:97)

                              at org.hibernate.internal.util.xml.XMLHelper.getDocumentFactory(XMLHelper.java:112)

                              at org.hibernate.envers.configuration.RevisionInfoConfiguration.generateDefaultRevisionInfoXmlMapping(RevisionInfoConfiguration.java:88)

                              at org.hibernate.envers.configuration.RevisionInfoConfiguration.configure(RevisionInfoConfiguration.java:326)

                              at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:95)

                              at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:135)

                              at org.hibernate.envers.event.EnversIntegrator.integrate(EnversIntegrator.java:63)

                              at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:294)

                              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)

                              at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)

                              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)

                              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)

                              at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)

                              at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)

                              at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)

                              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

                              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

                              ... 3 more

                     

                     

                    15:24:23,283 INFO  [org.jboss.as.server] (HttpManagementService-threads - 32) JBAS015870: Deploy of deployment "service-mobile.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.persistenceunit.\"service-mobile.war#kfv6DS_learn\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"service-mobile.war#kfv6DS_learn\": Failed to start service"}}

                    15:24:23,285 INFO  [org.jboss.as.controller] (HttpManagementService-threads - 32) JBAS014774: Service status report

                    JBAS014777:   Services which failed to start:      service jboss.persistenceunit."service-mobile.war#kfv6DS_learn": org.jboss.msc.service.StartException in service jboss.persistenceunit."service-mobile.war#kfv6DS_learn": Failed to start service

                     

                     

                    15:24:23,298 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment service-mobile.war in 12ms

                    • 7. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
                      Scott Marlow Master

                      I have a few more questions.

                       

                      1.  Do you know if your application is using Hibernate envers (auditing of entity changes)?  I'd like to see the contents of your persistence.xml.  You might need to try setting "hibernate.listeners.envers.autoRegister" to false, as a property setting in your persistence unit definition(s) in persistence.xml.

                       

                      2.  Which version of JBoss AS are you using? 

                       

                      3.  I don't think that the "Dependencies: org.dom4j export" in the war MANIFEST.MF is helping the Hibernate code to access the dom4j.  If you don't need it for other reasons, that could be removed (and test again).

                       

                      4. Have you tried to deploy against the latest AS7 nightly building? That would be another thing to try, just to make sure the cause hasn't already been addressed.

                      • 8. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
                        Dean Schulze Newbie

                        1.  I'm not using Hibernate envers.  My persistence.xml is below.  The project is small if you have somewhere I can upload it you can have the whole project.

                         

                        2.  JBoss AS 7.1.1 Final.

                         

                        3.  I get the same error with or without the "Dependencies: ..." in the manifest.mf.  That was one solution that somone offered on his blog.  It doesn't work and it has no effect.

                         

                        4.  No.  That would involve configuring the new server (deploying modules, etc.).  I'd like to avoid spending time doing that unless there is some reason to think it will work.

                         

                         

                        <?xml version="1.0" encoding="UTF-8"?>

                        <persistence

                                  version="2.0"

                                  xmlns="http://java.sun.com/xml/ns/persistence"

                                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                                  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

                         

                         

                                  <persistence-unit name="kfv6DS_learn" transaction-type="JTA">

                         

                         

                                            <provider>org.hibernate.ejb.HibernatePersistence</provider>

                                            <jta-data-source>java:/kfv6DS_learn</jta-data-source>

                         

                         

                                            <class>learn.entity.Answer</class>

                                            <class>learn.entity.AnswerHistory</class>

                                            <class>learn.entity.Context</class>

                                            <class>learn.entity.ExternalRequest</class>

                                            <class>learn.entity.ExternalSession</class>

                                            <class>learn.entity.LearningUnitState</class>

                                            <class>learn.entity.LearningUnitStatePK</class>

                                            <class>learn.entity.Patch</class>

                                            <class>learn.entity.Question</class>

                                            <class>learn.entity.QuestionHistory</class>

                                            <class>learn.entity.Session</class>

                                            <class>learn.entity.StateTransition</class>

                                            <class>learn.entity.StateTransitionPK</class>

                                            <class>learn.entity.Throttle</class>

                         

                         

                                            <properties>

                                                      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />

                                                      <!-- Logs SQL statements generated by Hibernate. For development only.

                                                                Be sure this is off in production. -->

                                                      <!-- <property name="hibernate.show_sql" value="true" /> -->

                                            </properties>

                         

                                  </persistence-unit>

                         

                         

                        </persistence>

                        • 9. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
                          Dean Schulze Newbie

                          I deployed the learn-entity-6.2.0-SNAPSHOT.jar file to JBoss and when I enabled it I got the same Exception.  So the problem is the entity .jar file.  The .war file is not the source of the problem.

                           

                          Also, I was able to deploy the .war file to Glassfish 3.1.2.  This looks like a problem with Hibernate 4.0 or Hibernate 4.0 integration with JBoss AS 7.1.1.

                          • 10. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
                            Scott Marlow Master

                            If you want to make a copy of your war archive available to me, I'll try deploying it locally.  This smells like a bug but perhaps I'm missing something in my attempt to help. 

                             

                            You could attach it to this forum (publicly) or email it to me.  Another public way is to create a dropbox account (the link is a referal for dropbox) and post the link here. 

                            • 12. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
                              Dean Schulze Newbie

                              Scott - you put me on the right track when you changed the datasource to exampleDS and got it to deploy.

                               

                              The dom4j Exception was caused by having an incorrect port number in the <datasource> element in standalone.xml.  When I corrected the port number I could deploy and enable the entity .jar file.

                               

                              I tried to reproduce this problem by undeploying the entity .jar file, stopping JBoss, and putting the incorrect port number in the <datasource> element.  This time I got a meaningful

                              Exception showing that JBoss could not obtain a managed connection for the <datasource>.

                               

                              The meaningless dom4j Exception only occurs before the archive gets deployed for the first time with the correct datasource.  On subsequent deployments if the wrong datasource port is specified JBoss gives a meaningful exception.  The meaningless exception goes away after the archive is deployed the first time with the correct datasource.

                               

                              Ridiculous.

                              • 13. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
                                Shaun O'Hagan Newbie

                                Thankyou for pointing ME in the vague direction of fixing this crazy issue. It almost drove me insane.  Having gone through the pain of getting Arqullian working in Wildfly 8 using EJBs, Drools, JPA an embedded Derby deployment I returned to running up the main app to be hit with this dom4j issue.  Based on your experience I looked at my standalone.xml DataSource config and couldn't see anything wrong.  I chopped it all out and started adding it back in bit by bit whilst testing with a very stripped down JPA Eclipse Project which was failing with this issue.  Then it started working !.  The problem ?  Well when configuring the Derby DataSource I had ripped out the un-needed H2 one but had left the associated H2 driver definition behind.  Why that would cause the error in question who knows.  Classic JEE insanity.

                                 

                                UPDATE

                                ------------

                                The problem returned after being OK for a while. Above was a red herring - now the "fix" is to open up standalone.xml in an editor and save it and restart the server.  Maybe the server is monkeying around with the file on start up and trashing stuff - the server definitely rewrites the file from time to time as we have probably all observed.

                                • 14. Re: Hibernate Entity .jar gives Exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
                                  chandra pawar Newbie

                                  Sounds crazy but perfect solution. It worked great after editing standalone.xml (no change just added blank space) and restart the server.