3 Replies Latest reply on Nov 1, 2015 1:39 PM by gengis

    HibernateProxy not in classpath if persistence.xml is missing

    gengis

      Dear all,

       

      I noticed that HibernateProxy is not in classpath if persistence.xml is missing.

       

      It results in NoClassDefFound error when a web projets calls a remote EJB and receives from him entities loaded by Hibernate.

      If one of these entities has a lazy manyToOne association (I guess it is the same for oneToOne) then the entity cannot be deserialized in the web project because HibernateProxy is not in the classpath.

       

      It is not specific to web projet, Class.forName("org.hibernate.proxy.HibernateProxy") fails if persistence.xml is not in META-INF in the classpath. It works with a persistence..xml (even a very basic one, without any datasource, just a dummy persistence unit).

       

      Is it possible to configure Wildfly to tell him that loading hibernate jar is mandatory and should not only happen when persistence.xml is present ?

       

      Many thanks !

        • 1. Re: HibernateProxy not in classpath if persistence.xml is missing
          jaysensharma

          It is very easy to tell WildFly to do so, using the WildFly class loading feature.

           

          For example if you add the following kind of "$YourWebApp/WEB-INF/jboss-deployment-structure.xml" in your application then your application can access hibernate classes even without using persistence.xml

           

          <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
              <deployment>
                  <dependencies>
                      <module name="org.hibernate" />
                  </dependencies>
              </deployment>
          </jboss-deployment-structure>
          

           

          See: https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly

          • 2. Re: HibernateProxy not in classpath if persistence.xml is missing
            jaysensharma

            Additionally if you do not want to add any additionally file like "jboss-deployment-structure.xml" inside your Application archives then you can do it globally at WildFly level by declaring a global-module inside the "ee" subsystem:

             

            CLI command:

            /subsystem=ee:write-attribute(name="global-modules",value=[{"name" => "org.hibernate","slot" => "main"}])
            

             

            XML Snippet:

                    <subsystem xmlns="urn:jboss:domain:ee:2.0">
                        <global-modules>
                            <module name="org.hibernate" slot="main"/>    <!-- NOTICE this -->
                        </global-modules>
                        <spec-descriptor-property-replacement>false</spec-descriptor-property-replacement>
                        .
                        .
                        .
                    </subsystem>
            
            • 3. Re: HibernateProxy not in classpath if persistence.xml is missing
              gengis

              Thanks Jay,

               

              I maked the first answer "correct" but it also needs :

               

              <module name="org.javassist" />

               

              I guess it is the same for the second answer.