2 Replies Latest reply on Oct 16, 2017 9:57 AM by Felipe Oliveira

    Jboss-eap-7 - java.lang.ClassNotFoundException: org.hibernate.proxy.HibernateProxy

    Felipe Oliveira Newbie

      Hi,

       

      I want to make a "shared library" concept just like in WAS servers so I created a module with all libraries installed in my Jboss EAP 7.1. One of my them is hibernate-core-5.2.10.Final.

       

      I know that jboss has a module for hibernate, but in my installation its in 5.0.9 version.

       

      When I try to run my application and build my session Factory, the AS shows this error in the log.

      2017-10-11 18:36:52 ERROR stderr:71 - Caused by: javassist.CannotCompileException: by java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy
      2017-10-11 18:36:52 ERROR stderr:71 - at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:170)
      2017-10-11 18:36:52 ERROR stderr:71 - at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:507)
      2017-10-11 18:36:52 ERROR stderr:71 - ... 131 more
      2017-10-11 18:36:52 ERROR stderr:71 - Caused by: java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy
      2017-10-11 18:36:52 ERROR stderr:71 - at java.lang.ClassLoader.defineClass1(Native Method)
      2017-10-11 18:36:52 ERROR stderr:71 - at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
      2017-10-11 18:36:52 ERROR stderr:71 - at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2017-10-11 18:36:52 ERROR stderr:71 - at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      2017-10-11 18:36:52 ERROR stderr:71 - at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      2017-10-11 18:36:52 ERROR stderr:71 - at java.lang.reflect.Method.invoke(Method.java:498)
      2017-10-11 18:36:52 ERROR stderr:71 - at javassist.util.proxy.FactoryHelper.toClass2(FactoryHelper.java:182)
      2017-10-11 18:36:52 ERROR stderr:71 - at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:164)
      2017-10-11 18:36:52 ERROR stderr:71 - ... 132 more
      2017-10-11 18:36:52 ERROR stderr:71 - Caused by: java.lang.ClassNotFoundException: org.hibernate.proxy.HibernateProxy from [Module "deployment.SATI-Devec.ear.SATI-Devec-business-0.0.1.jar:main" from Service Module Loader]
      2017-10-11 18:36:52 ERROR stderr:71 - at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
      2017-10-11 18:36:52 ERROR stderr:71 - at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
      2017-10-11 18:36:52 ERROR stderr:71 - at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
      2017-10-11 18:36:52 ERROR stderr:71 - at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
      2017-10-11 18:36:52 ERROR stderr:71 - ... 140 more
      

       

      My Module.xml:

       

      <module xmlns="urn:jboss:module:1.3" name="br.libraries.libs" slot="0.0.1">
      
        <resources>
          <resource-root path="all-themes-1.0.10.jar"/>
          <resource-root path="antlr-2.7.7.jar"/>
          <resource-root path="aspectjrt-1.8.7.jar"/>
          <resource-root path="bcprov-jdk16-1.46.jar"/>
          <resource-root path="botdetect-4.0.beta3.jar"/>
          <resource-root path="botdetect-servlet-4.0.beta3.jar"/>
          <resource-root path="byte-buddy-1.6.6.jar"/>
          <resource-root path="classmate-1.3.0.jar"/>
          <resource-root path="commons-lang3-3.1.jar"/>
          <resource-root path="dom4j-1.6.1.jar"/>
          <resource-root path="gson-2.2.4.jar"/>
          <resource-root path="hamcrest-core-1.1.jar"/>
          <resource-root path="hibernate-commons-annotations-5.0.1.Final.jar"/>
          <resource-root path="hibernate-core-5.2.10.Final.jar"/>
          <resource-root path="hibernate-entitymanager-5.2.10.Final.jar"/>
          <resource-root path="hsqldb-2.3.4.jar"/>
          <resource-root path="jandex-2.0.3.Final.jar"/>
          <resource-root path="javassist-3.20.0-GA.jar"/>
          <resource-root path="javax.mail-api-1.6.0.jar"/>
          <resource-root path="jboss-logging-3.3.0.Final.jar"/>
          <resource-root path="jboss-transaction-api_1.2_spec-1.0.1.Final.jar"/>
          <resource-root path="jsf-api-2.2.10.jar"/>
          <resource-root path="jsf-impl-2.2.10.jar"/>
          <resource-root path="json-20160810.jar"/>
          <resource-root path="junit-4.9.jar"/>
          <resource-root path="log4j-1.2.17.jar"/>
          <resource-root path="ojdbc7-12.1.0.2.jar"/>
          <resource-root path="primefaces-6.1.jar"/>
          <resource-root path="primefaces-extensions-6.1.1.jar"/>
          <resource-root path="simple-botdetect-jsp20-4.0.beta3.jar"/>
          <resource-root path="slf4j-api-1.7.25.jar"/>
          <resource-root path="slf4j-log4j12-1.7.5.jar"/>
        </resources>
      
      
        <dependencies> 
          <module name="javax.api"/>
          <module name="javax.validation.api"/>
          <module name="org.javassist"/>  
          <module name="javax.persistence.api"/>
          <module name="javax.transaction.api"/>
          <module name="javax.xml.bind.api"/>
        </dependencies>
      
      </module>
      
      

       

      The manifest from SATI-Devec-business:

      Manifest-Version: 1.0
      Built-By: fmsoliveira
      Class-Path: simple-botdetect-jsp20-4.0.beta3.jar botdetect-servlet-4.0
       .beta3.jar botdetect-4.0.beta3.jar hsqldb-2.3.4.jar
      Created-By: Apache Maven 3.5.0
      Build-Jdk: 1.8.0_131
      dependencies: br.libraries.core:0.0.1
      

       

      Anyone knows how can I avoid this type of error? I just want to use my libraries instead of the standard libraries from Jboss.

       

      Thanks!

        • 1. Re: Jboss-eap-7 - java.lang.ClassNotFoundException: org.hibernate.proxy.HibernateProxy
          Anup Dey Expert

          At its root, this is a classic Classloading Issue .. The solution depends on the version of Hibernate you are using.

           

          Hibernate 4.X

          You must set the ProxyFactory classLoaderProvider to provide a class loader that includes

          1. Your entity classes
          2. Hibernate Proxy (org.hibernate.proxy)
          3. Javassist proxy (javassist.util.proxy)

          Hibernate 5.X

          Hibernate now uses the classloader of the entity class in the proxy factory. You must include Hibernate proxy (org.hibernate.proxy) and Javassist (javassist.util.proxy) which may be different from the bundle that creates the EntityManagerFactory.

           

          To have org.hibernate.proxy.HibernateProxy in classpath, add this dependency to pom.xml:

           

          ~~~

          <dependency>

                      <groupId>org.hibernate</groupId>

                      <artifactId>hibernate-core</artifactId>

                      <version>5.2.10.Final</version>

            </dependency>

          ~~~

           

          There may be possibility muliple version of hibernate libraries present in your system classpath.  Above kind of exceptions can be encountered if the persistence unit (persistence.xml) is in a jar in the "$EAR/lib"directory , whereas the entities classes are in jars in the ear's root ($EAR).

           

          Restructure the EAR Application and make sure that the Persistence Unit and the Entity classes are placed as part of Jar file inside the "$EAR/lib" directory.

           

           

          Add <exclude-unlisted-classes>true</exclude-unlisted-classes> to persistence.xml

           

           

          Then include the classes you want with:

           

           

          <class>a.b.c</class>

          • 2. Re: Jboss-eap-7 - java.lang.ClassNotFoundException: org.hibernate.proxy.HibernateProxy
            Felipe Oliveira Newbie

            Hi Anup,

             

            Thanks for your response.

            Anup Dey escreveu:

             

            To have org.hibernate.proxy.HibernateProxy in classpath, add this dependency to pom.xml:

             

            ~~~

            <dependency>

            <groupId>org.hibernate</groupId>

            <artifactId>hibernate-core</artifactId>

            <version>5.2.10.Final</version>

            </dependency>

            I am already using this dependency in my pom.xml.

             

            Anup Dey escreveu:

             

            There may be possibility muliple version of hibernate libraries present in your system classpath. Above kind of exceptions can be encountered if the persistence unit (persistence.xml) is in a jar in the "$EAR/lib"directory , whereas the entities classes are in jars in the ear's root ($EAR).

             

            Restructure the EAR Application and make sure that the Persistence Unit and the Entity classes are placed as part of Jar file inside the "$EAR/lib" directory.

             

             

            Add <exclude-unlisted-classes>true</exclude-unlisted-classes> to persistence.xml

             

             

            Then include the classes you want with:

             

             

            <class>a.b.c</class>

            My EAR is already with the same that you described.  One thing is that I'm not using persistence.xml. I am using the classic Hibernate.cfg.xml. Is there a problem with this type of approach?

             

            My issue is:

            I don't want to deploy my EAR with all my dependencies inside it(My ear has 20MB with the libs). So I created a module with all my dependencies in the AS. I have seen some articles about this "classloading" issue, but I didn't find how I can resolve it using different versions of hibernate.