4

I've a gradle project which uses hibernate > 4 . If I run my war file in Apache tomcat, I don't get any error. But when I'm deploying it in Wildfly 8.2 , I get the following exception

Caused by: org.hibernate.InvalidMappingException: Error while parsing file: /G:/wildfly-8.2.0.Final/bin/content/mywar-1.0.war/WEB-INF/classes/com/mysite/
hbm/Role.hbm.xml
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1182) [hibernate-ent
itymanager-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:848) [hibernate-entitymanager-4.3.7.Fi
nal.jar:4.3.7.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845) [hibernate-entitymanager-4.3.7.Fi
nal.jar:4.3.7.Final]
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) [hibernate-core-4.3.7.Final.jar:4.
3.7.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) [hibernate-entitymanager-4.3.7.Final.
jar:4.3.7.Final]
        at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
        ... 8 more
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
        at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:375) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:304) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration.add(Configuration.java:518) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration.add(Configuration.java:514) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration.add(Configuration.java:688) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:726) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1177) [hibernate-ent
itymanager-4.3.7.Final.jar:4.3.7.Final]
        ... 14 more
Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception: org.dom4j.DocumentFactory cannot
 be cast to org.dom4j.DocumentFactory
        at org.dom4j.io.SAXReader.read(SAXReader.java:484) [dom4j-1.6.1.jar:1.6.1]

I just added a exclude in my Gradle file like

runtime.exclude group: "dom4j" 

Now when I run gradle build, dom4j.jar is not created in the war file. Now I can run my deploy and run my project successfully on Wildfly 8.2 without any error. But the real problem starts here.

One of the feature in my project is that, it'll copy a file.xlsm to anotherfile.xlsm where I'm using jars like Apache Poi for those purposes. Here, Apache Poi is trying to access a method in dom4j.jar during file processing, it results in the following error

18:40:13,261 ERROR [io.undertow.request] (default task-29) UT005023: Exception handling request to /app/parentPath/myAction: org.springframework.web.util.NestedSe
rvletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
        at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1287) [spring-webmvc-4.1.4.RELEASE.jar:4.1.4
.RELEASE]

Any ideas how I can permanently use dom4j.jar inside my classpath? I've searched for many question and most of them suggested to remove dom4j from classpath. I do successfully run my program by removing it from classpath but it results in the above error during excel file processing. Wasted more than a day on this..!! IS it possible to include dom4j.jar in my classpath?

Update:

I've done a little trick in MANIFEST.MF file. I've opened mywar.war > META-INF > MANIFEST.MF

and added Dependencies: org.dom4j export at the end of the file and saved it. So if I deploy my war file, I'm successfully running it without any error.

Can someone explain where I've to add this kind of property in my src/ file so that it will be automatcially added to MANIFEST.MF after gradle build..

The Coder
  • 2,562
  • 5
  • 33
  • 62

2 Answers2

6

This exception on wildfly usually occurs when you include a hibernate lib in your war that's different from the wildfly one, since you are deploying to wildfly it already include hibernate so you can set you live as provided in gradle aka compileProvided and deploy without exporting the dependence. If you still got the same error try declaring the hibernate dependency on manifest but keep the lib as provided it should work fine.

Kennedy Oliveira
  • 2,141
  • 2
  • 20
  • 25
  • Thanks for your reply Kennedy Oliveira. Atleast now I know the real reason which is causing this error. Btw, I've solved this by adding jboss-deployment-structure.xml which have the following contents ` ` – The Coder Mar 29 '15 at 19:38
  • 1
    @user1354678, your welcome! The way you solved looks like a work around the problem, if you 'll just deploy you project in wildfly the best solution as i said is to make your hibernate lib provided and you can include in you jboss-deployment structure the dependency of hibernate. Anyway, i'm glad to help! – Kennedy Oliveira Mar 29 '15 at 19:44
  • Kennedy Oliveira. I've been facing the same problem, with a RESTful project in java, trying to deploy in wildfly. I understood the problem, but it would be of great help if you could put some reference how to declare such dependency. – pablo.vix Sep 02 '15 at 14:55
  • Hello Pablo! It's just a maven dependency you need to put the scope of all your hibernate dependency as provided so it doesn't conflict with the one that wildfly auto load – Kennedy Oliveira Sep 04 '15 at 23:36
0

I had this same problem and i know how frustrating this one can be. I was able to resolve this problem. see my answer here. Hope this help

Community
  • 1
  • 1
Rasheed
  • 991
  • 1
  • 12
  • 18