1
votes

I'm using Wildfly with Spring 4.1.6 and Hibernate 4.3.2 in an ear project and I get this exception:

    ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.subunit."ear.ear"."ear.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."ear.ear"."ear.war".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of subdeployment "ear.war" of deployment "ear.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_75]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_75]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_75]
     Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011440: Can't find a persistence unit named org.hibernate.tutorial.jpa in subdeployment "ear.war" of deployment "ear.ear"
at org.jboss.as.jpa.processor.PersistenceRefProcessor.getPersistenceUnitBindingSource(PersistenceRefProcessor.java:212)
at org.jboss.as.jpa.processor.PersistenceRefProcessor.getPersistenceUnitRefs(PersistenceRefProcessor.java:127)
at org.jboss.as.jpa.processor.PersistenceRefProcessor.processDescriptorEntries(PersistenceRefProcessor.java:78)
at org.jboss.as.ee.component.deployers.AbstractDeploymentDescriptorBindingsProcessor.deploy(AbstractDeploymentDescriptorBindingsProcessor.java:95)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.2.0.Final.jar:8.2.0.Final]
... 5 more

My persistence.xml in the ear project located in META-INF folder:

     <persistence-unit name="ear" transaction-type="JTA">
     <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>jboss/jpaDS</jta-data-source>
    <jar-file>Jar/ear_jar.jar</jar-file>
    <properties>
        <property name="hibernate.current_session_context_class" value="jta"/>
        <property name="hibernate.id.new_generator_mappings" value="true"/>
        <property name="hibernate.dialect"      value="org.hibernate.dialect.Dialect"/>
        <property name="hibernate.show_sql"     value="true"/>
        <property name="hibernate.format_sql"   value="true"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/>               
    </properties>
    </persistence-unit>
    </persistence>

My persistence.xml in the war project located in META-INF folder:

    <persistence-unit name="org.hibernate.tutorial.jpa" transaction-type="JTA"> 
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>jboss/jpaDS</jta-data-source> 
      <class>main.java.com.model.User</class>
      <exclude-unlisted-classes>false</exclude-unlisted-classes>
      <properties>
        <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
        <property name="javax.persistence.jdbc.url" value="C:\Users\alexandra\MyDB;create=true"/>
        <property name="javax.persistence.jdbc.user" value="user"/>
        <property name="javax.persistence.jdbc.password" value="password"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Dialect"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/>
        <property name="hibernate.connection.release_mode" value="after_statement"/>
        <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JDBCTransactionFactory"/>  
        <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup" />
        <property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/> 
        <property name="connection.pool_size" value="1"/>
        <property name="current_session_context_class" value="thread"/>
        <property name="cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
        <property name="show_sql" value="true"/>
        <property name="jboss.as.jpa.providerModule" value="hibernate3-bundled" />
        <property name="hibernate.current_session_context_class" value="thread"/>
        <property name="jboss.as.jpa.managed" value="false"/>
        <property name="javax.persistence.validation.mode" value="none"/>
        <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
        <property name="hibernate.current_session_context_class" value="jta"/>
      </properties>
     </persistence-unit>
    </persistence>

EDIT:

My jboss-deployment-structure.xml of the ear:

    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
      <deployment>
       <dependencies>
        <module name="deployment.Ear.ear.ear_jar.jar" export="true" />
       </dependencies>
      </deployment>

     <sub-deployment name="War/ear.war" >
      <resources>
       <resource-root path="War/ear.war"/>
     </resources>
     <local-last value="true" />
   </sub-deployment>

    <sub-deployment name="Jar/ear_jar.jar" >
      <resources>
        <resource-root path="Ear/ear_jar.jar" />
      </resources>

   </sub-deployment>

  </jboss-deployment-structure>

My User file:

     import javax.persistence.Column;
     import javax.persistence.Entity;
     import javax.persistence.GeneratedValue;
     import javax.persistence.GenerationType;
     import javax.persistence.Id;
     import org.springframework.context.annotation.Bean;
     import org.springframework.format.annotation.NumberFormat;
     import org.springframework.format.annotation.NumberFormat.Style;
     import org.springframework.stereotype.Repository;

     @Entity(name = "REGISTRY.register")  
     @Repository
     public class User implements Serializable {

    public static final long serialVersionUID = 1L;
    @Column(name = "name",insertable = false)
    private String name;
    @Column(name = "password",insertable = false)
    private String password;
    @Id
    @NumberFormat(style = Style.NUMBER) 
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int ID;
    // getters and setters
1

1 Answers

0
votes

That is pretty simple (at least I hope it is ;) ). There is a classloader hierarchy, so that the classloader that is "above" in the hierarchy cannot load the objects that are lower in the hierarchy, however those that are lower, can load objects above them.

ie. The EAR classloader is above the WAR classloader. So the classes that are loaded in EAR cannot load objects from WAR. But the WAR objects can load objects from EAR.

I suppose, that since You got the persistence.xml in the EAR, You also put hibernate dependencies in the EAR, and so they cannot load objects from WAR.

If this is true, then I would suggest trying to move hibernate dependencies to WAR and see if it works, or reorganizing Your EAR/WAR with classloader hierarchy in mind :)