3 Replies Latest reply on Feb 26, 2007 4:59 PM by mikebaranczak

    Strange IllegalAccessError with JBoss + Hibernate

    gbilodeau

      Hi guys,

      I'm getting the following error when loading up my application on JBoss 4.0.5:

      java.lang.IllegalAccessError: tried to access method org.hibernate.cfg.Mappings.<init>(Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/List;Ljava/util/List;Lorg/hibernate/cfg/NamingStrategy;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/List;Ljava/util/Map;Ljava/util/Map;)V from class org.hibernate.cfg.ExtendedMappings
       at org.hibernate.cfg.ExtendedMappings.<init>(ExtendedMappings.java:65)
       at org.hibernate.cfg.AnnotationConfiguration.createExtendedMappings(AnnotationConfiguration.java:166)
       at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:254)
       at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1039)
       at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1211)
       at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
       at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:847)
       at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:385)
       at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
      


      This application is running fine on Tomcat 5.5 and Glassfish (Sun JSAS 9.0), but not on JBoss.

      Looking at the code, I see that the two classes (Mappings and ExtendedMappings) are declared to be in the same package (org.hibernate.cfg) but are located in 2 different JARs (Hibernate and Annotations). Maybe this is enforced more strictly by JBoss?

      I'm running on Java 5, JBoss 4.0.5GA, Hibernate 3.2GA, Hibernate Annotations 3.2GA and Hibernate EntityManager 3.2GA. All the libraries are correctly deployed and there is no mistake in using a release candidate instead of the final release.

      Any ideas?

      Thanks,
      GB


        • 1. Re: Strange IllegalAccessError with JBoss + Hibernate
          leizhu

          The problem is the the Mapping construction is default. Your annotation class is probably not in the lib directory and are loaded by different class loader. So even though the invoking class is in the same package, the a class in the annotation jar cannot call the default constructor loaded by another class loader. Try to move your hibernate annotation jar to the lib directory.

          TS

          • 2. Re: Strange IllegalAccessError with JBoss + Hibernate
            gbilodeau

            Hi and thanks for your answer. Currently all my Hibernate libraries (Core, Annotations and EntityManager) are packaged in my EAR root - this packaging seems to be working fine on other app servers. Is the conflict due to the presence of the hibernate3.jar and jboss-hibernate.jar files in the ${JBOSS_HOME}/server/default/lib directory? And is this previous directory the "lib" directory you're mentioning in your message?

            • 3. Re: Strange IllegalAccessError with JBoss + Hibernate
              mikebaranczak

              I just got bit by the same problem.

              Copy hibernate-annotations.jar and ejb3-persistence.jar to ${JBOSS_HOME}/server/default/lib. (Not sure why that second one is necessary, but if it's just in your application's lib directory, it won't work.) In other words, all your Hibernate-related classes have to be loaded from the same place.