0

I am trying to deploy a Spring-JPA-Hibernate web application on Wildfly. First, I had problems with Hibernate which seemed to go away with

<jboss-deployment-structure>
  <deployment>
    <exclusions>
      <module name="org.hibernate" slot="main" />
    </exclusions>
    <dependencies>
      <module name="org.hibernate" />
    </dependencies>
  </deployment>
</jboss-deployment-structure>

then however, my org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean tried to parse its mappingResources (xml file), and I got the exception

Error while parsing (.... etc)

org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1163)
    ... 44 more
Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

which seems to suggest there is another dom4j on the classpath.

At this point I got lost, since tinkering again with jboss-deployment-structure.xml only made the server freeze with no error message soon after startup.

Is there a simple way just to tell Wildfly not to put on the classpath at least its dom4j (or better, not to add anything at all automatically)?

John Donn
  • 1,718
  • 2
  • 19
  • 45

1 Answers1

2

I think that you must choose a strategy to use the classes from Wildfly or to use the classes you provide in your application.

I have the similar issue with Liferay 6.2 GA3 deployed in Wildfly 8.2. I solved it using a deployment descriptor similar to:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
   <deployment>
      <exclusions>
         <module name="org.apache.log4j"/>
         <module name="org.hibernate"/>
         <module name="org.hibernate.validator"/>
         <module name="org.jboss.as.jpa"/>
         <module name="org.javassist"/>
         <module name="javaee.api"/>
      </exclusions>
      <dependencies>
         <!-- add the module and remove the dom4j in your application 
              or exclude the module and add the jar in your application -->
         <module name="org.dom4j"/>
         <module name="javax.mail.api"/>
         <module name="org.apache.xerces"/>
         <module name="org.jboss.modules"/>
      </dependencies>
   </deployment>
</jboss-deployment-structure>

https://www.liferay.com/community/forums/-/message_boards/view_message/40321431#_19_message_47754919

If you want to use the Wildfly classes and deploy the JPA entities in Wildfly container, use a similar persitence.xml

<?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="MyApp"  transaction-type="JTA" >
        <!-- Data Source -->
        <jta-data-source>java:jboss/datasources/MyApplicationPool</jta-data-source>

    <!-- Class -->
    <class>entities here </class>

    <!-- Properties -->
    <properties>
        <!-- the persitence unit will be deployed in Wildfly and linked to spring 
            using JNDI https://docs.jboss.org/author/display/WFLY8/JPA+Reference+Guide#JPAReferenceGuide-BindingEntityManagerFactory%2FEntityManagertoJNDI -->
        <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/WildflyEntityManagerFactory" />
        <property name="jboss.entity.manager.jndi.name" value="java:/WildflyEntityManagerVMS" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        <!-- for the JODA datetime -->
        <property name="jadira.usertype.autoRegisterUserTypes" value="true" />
    </properties>
</persistence-unit>

Make reference to the Wildfly persitence unit in your Spring application:

<bean id="transactionManager"
    class="org.springframework.transaction.jta.JtaTransactionManager">
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />
<jee:jndi-lookup id="entityManagerFactory"
    jndi-name="java:jboss/WildflyEntityManagerFactory" expected-type="javax.persistence.EntityManagerFactory" />

And you should not need any specific jboss-deployment-structure.

deleze
  • 661
  • 1
  • 7
  • 8