1 2 Previous Next 22 Replies Latest reply on Oct 25, 2007 9:52 AM by jaikiran Go to original post
      • 15. Re: Overriding universal classloader, JBoss 4.2.1GA
        jimpo

        OK, I managed to create a trimmed down version of my application. There's still plenty of JAR's (the war is 11MB), but only 3 classes and just a few config files.

        http://rapidshare.com/files/62738527/myproject-1.0-SNAPSHOT.war.html

        Once you have deployed the war, you should be able to go to

        http://localhost:8080/myproject-1.0-SNAPSHOT/mainMenu.html or
        http://localhost:8080/mainMenu.html

        (depending on whether you are using tomcat or jboss)

        and see a list of users from app_user database table. app_user should have two fields, "id" and "username". This war assumes you have MySQL running on localhost, and have user "root" with password "erofog". Or you may change the username and password in jdbc.properties in WEB-INF/classes/

        You should be able to see whether you get deploy-time classloading errors or not, even if you don't have a MySQL server at all. So mysql is not really necessary. If you don't have mysql you will still get some deployment time errors, but deployment should be successfull and you can access the page and get something like:

        javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection

        I have tested on

        1. tomcat 6.0.14 - works fine
        2. JBoss 4.0.3SP1 - works fine
        3. JBoss 4.2.1.GA - I get:

        18:31:25,093 INFO [Version] Hibernate Validator 3.0.0.GA
        18:31:25,203 INFO [DefaultListableBeanFactory] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@18845af: defi
        ning beans [transactionManager,userDao,urlMapping,listUsersController,viewResolver,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcess
        or,entityManagerFactory,persistenceUnitManager,propertyConfigurer,dataSource,org.springframework.aop.config.internalAutoProxyCreator,controllerTx,org.sprin
        gframework.transaction.aspectj.AnnotationTransactionAspect,txAdvice]; root of factory hierarchy
        18:31:25,203 ERROR [DispatcherServlet] Context initialization failed
        org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.aspectj.AnnotationTransactionAspect
        ' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'transactionManager' while setting bean property '
        transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' define
        d in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entity
        ManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined
        in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hiber
        nate.search.event.FullTextIndexEventListener
        Caused by:
        org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/di
        spatcher-servlet.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.
        springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/disp
        atcher-servlet.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.search.event.FullTextIndexEventListe
        ner
        Caused by:
        org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/
        dispatcher-servlet.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.search.event.FullTextIndexEventL
        istener
        Caused by:
        java.lang.ClassCastException: org.hibernate.search.event.FullTextIndexEventListener
         at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:856)
         at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
         at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
         at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:
        218)
         at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:251)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1201)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1171)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:261)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1099)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:861)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421)
         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:261)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1099)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:861)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421)
         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
         at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:287)
         at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
         at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:331)
         at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:265)
         at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:235)
         at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126)
         at javax.servlet.GenericServlet.init(GenericServlet.java:212)
         at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
         at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
         at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4069)
         at org.apache.catalina.core.StandardContext.start(StandardContext.java:4373)
         at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
         at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
         at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
         at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
         at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
         at org.apache.catalina.core.StandardContext.init(StandardContext.java:5310)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
         at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
         at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
         at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
         at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
         at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
         at org.jboss.web.WebModule.startModule(WebModule.java:83)
         at org.jboss.web.WebModule.startService(WebModule.java:61)
         at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
         at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
         at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
         at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
         at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
         at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
         at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
         at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
         at $Proxy0.start(Unknown Source)
         at org.jboss.system.ServiceController.start(ServiceController.java:417)
         at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
         at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
         at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
         at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
         at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
         at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
         at $Proxy45.start(Unknown Source)
         at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
         at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
         at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
         at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
         at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
         at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
         at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
         at org.jboss.ws.integration.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:93)
         at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
         at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
         at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
         at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
         at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
         at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
         at $Proxy46.start(Unknown Source)
         at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
         at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
         at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
         at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
         at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
         at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
         at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
         at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
         at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
         at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
         at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
         at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
         at $Proxy9.deploy(Unknown Source)
         at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
         at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
         at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
         at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
         at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
        18:31:25,296 ERROR [[/]] StandardWrapper.Throwable
        org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.aspectj.AnnotationTransactionAspect
        ' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'transactionManager' while setting bean property '
        transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' define
        d in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entity
        ManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined
        in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hiber
        nate.search.event.FullTextIndexEventListener
        Caused by:
        
        


        • 16. Re: Overriding universal classloader, JBoss 4.2.1GA
          jimpo
          • 17. Re: Overriding universal classloader, JBoss 4.2.1GA
            jaikiran

            Thanks for creating that sample application. I will give it a try.

            • 18. Re: Overriding universal classloader, JBoss 4.2.1GA
              jaikiran

              Good news !!! It works now :) The application deploys fine without errors. I havent tried any of the functionality of the same application that you mailed me. Here's the changes that i had to do to get it working(point#2 below is which got it working) :

              1) Removed the commons-logging-xxx.jar from the WEB-INF/lib folder of the application. Having this in the application's lib folder causing some known exceptions (however this wasn't why you were getting the java.lang.ClassCastException: org.hibernate.search.event.FullTextIndexEventListener).

              2) The hibernate-annotations.jar file which comes with JBoss-4.2.1 is of Version: 3.2.1.GA. This jar contains the org.hibernate.search..... package. This package (one of its sub-package) contains the FullTextIndexEventListener class. However the version of hibernate-annotations that your application is using is of Version: 3.3.0.GA. If you look at the contents of this jar the org.hibernate.search package does not exist. Looking at the Hibernate download site (http://www.hibernate.org/6.html), this package now comes bundled through the "Hibernate Search" project, which has its own jar named hibernate-search.jar (the version is 3.0.0.GA).
              So, your application should also include this jar. I copied the hibernate-search.jar to the WEB-INF/lib folder of your application and started the deployment. It went past this error and ran into a class not found exception for a Lucene related class. Apparently, you also need the lucene-core-2.2.0.jar that comes bundled with hibernate-search project, in the application classpath. So i copied this lucene-core-2.2.0.jar to the WEB-INF/lib folder of the application. Then redeployed the application. Everything went fine and the application deployed successfully.

              I will mail you the modified war file so that you can look at the changes. In the meantime i will try to figure out why the search event listener functionality (which as far as i know is optional) was being used by Hibernate even though the application wasn't explicitly setting the requisite property.

              • 19. Re: Overriding universal classloader, JBoss 4.2.1GA
                jimpo991

                 

                "jaikiran" wrote:
                Good news !!! It works now :) The application deploys fine without errors. I havent tried any of the functionality of the same application that you mailed me. Here's the changes that i had to do to get it working(point#2 below is which got it working) :

                1) Removed the commons-logging-xxx.jar from the WEB-INF/lib folder of the application. Having this in the application's lib folder causing some known exceptions (however this wasn't why you were getting the java.lang.ClassCastException: org.hibernate.search.event.FullTextIndexEventListener).

                2) The hibernate-annotations.jar file which comes with JBoss-4.2.1 is of Version: 3.2.1.GA. This jar contains the org.hibernate.search..... package. This package (one of its sub-package) contains the FullTextIndexEventListener class. However the version of hibernate-annotations that your application is using is of Version: 3.3.0.GA. If you look at the contents of this jar the org.hibernate.search package does not exist. Looking at the Hibernate download site (http://www.hibernate.org/6.html), this package now comes bundled through the "Hibernate Search" project, which has its own jar named hibernate-search.jar (the version is 3.0.0.GA).
                So, your application should also include this jar. I copied the hibernate-search.jar to the WEB-INF/lib folder of your application and started the deployment. It went past this error and ran into a class not found exception for a Lucene related class. Apparently, you also need the lucene-core-2.2.0.jar that comes bundled with hibernate-search project, in the application classpath. So i copied this lucene-core-2.2.0.jar to the WEB-INF/lib folder of the application. Then redeployed the application. Everything went fine and the application deployed successfully.

                I will mail you the modified war file so that you can look at the changes. In the meantime i will try to figure out why the search event listener functionality (which as far as i know is optional) was being used by Hibernate even though the application wasn't explicitly setting the requisite property.


                Wow - great stuff! I am impressed how much effort you put towards solving this. I will test this on my side.

                I still don't understand why all this results in a ClassCastException about FullTextIndexEventListener. If my war uses the hibernate jars from WEB-INF, and they don't contain org.hibernate.search package, where does the classcastexception come from?

                • 20. Re: Overriding universal classloader, JBoss 4.2.1GA
                  jaikiran

                   

                  "jimpo991" wrote:

                  I still don't understand why all this results in a ClassCastException about FullTextIndexEventListener. If my war uses the hibernate jars from WEB-INF, and they don't contain org.hibernate.search package, where does the classcastexception come from?


                  Valid question. I hadn't completely got an answer to that yesterday so i had intentionally left out the explanation for the classcast from my earlier post. But now, after going through the Hibernate Annotations code and adding some log statements and enabling verbose class logging, i guess i understand what the issue is. Let me try to put it here. Let's consider the case where you did NOT place the hibernate-search.jar file in the WEB-INF/lib of your application:

                  1) Where in the code does this classcast occur- The name of the class where this happens is AnnotationConfiguration.java (which is part of the hibernate-annotationsxxx.jar). The lines of the code are (just copied the relevant part here - see the line marked in bold):

                  try {
                   searchEventListenerClass = ReflectHelper.classForName(
                   "org.hibernate.search.event.FullTextIndexEventListener",
                   AnnotationConfiguration.class );
                  
                  }
                  ...//some code here
                  PostInsertEventListener[] listeners = getEventListeners().getPostInsertEventListeners();
                  newListeners[length-1] = (PostInsertEventListener) searchEventListener;
                  ...//some more code here
                  
                  


                  So when the FullTextIndexEventListener is being cast to PostInsertEventListener, the classcast is being thrown. But looking at the FullTextIndexEventListener class definition, it infact does implement this interface:

                  public class FullTextIndexEventListener implements PostDeleteEventListener, PostInsertEventListener,
                   PostUpdateEventListener, Initializable {
                  


                  As you have been wondering, since the FullTextIndexEventListener is available ONLY in the hibernate-annotations.jar file present in the server/lib folder, how could it be that the FullTextIndexEventListener be loaded by 2 different classloaders. A bit of verbose class logs revealed that it was not the FullTextIndexEventListener that was loaded by different classloaders. It turned out that the PostInsertEventListener was being loaded by different classloaders. Here's the reason - The PostInsertEventListener is part of the hibernate (core) jar. The hibernate jar is present in the server/lib folder as well as the application's WEB-INF/lib folder. The PostInsertEventListener was once loaded by the application specific classloader. Then when the following code was executed

                  searchEventListenerClass = ReflectHelper.classForName(
                   "org.hibernate.search.event.FullTextIndexEventListener",
                   AnnotationConfiguration.class );


                  the FullTextIndexEventListener (present in hibernate-annotations.jar in server/lib) got loaded by the parent classloader since it was not present in your application's WEB-INF/lib folder. While loading this class, the server also loaded (again) the PostInsertEventListener (remember the FullTextIndexEventListener implements this interface) , this time using the classloader which loaded FullTextIndexEventListener - which turns out to be the parent classloder (since the parent classloader was used, it picked up this interface from the hibernate3.jar present in the server/lib folder and not the hibernate-3.2.5.jar present in the WEB-INF/lib of your application). Ultimately, the PostInsertEventListener was loaded by 2 different classloaders through the hibernate3.jar (in server/lib) and hibernate-3.2.5.jar (in WEB-INF/lib). This resulted in the classcast.

                  Adding the hibernate-search.jar to WEB-INF/lib solves the problem because, the FullTextIndexEventListener (and eventually the PostInsertEventListener ) will be loaded by the application specific classloader instead of the parent classloader.

                  Makes sense?



                  • 21. Re: Overriding universal classloader, JBoss 4.2.1GA
                    jimpo

                     

                    "jaikiran" wrote:


                    Makes sense?



                    Beautiful explanation of the issue. To recap, my understanding of the issue

                    - AnnotationConfiguration class (from hibernate-annotations, included in WEB-INF/lib) references Interface A and, if one exists, class B implementing interface A
                    - AnnotationConfiguration works even if class B does not exist
                    - interface A is loaded by the application classloader
                    - class B does not exist in the war. AnnotationConfiguration causes class B to be loaded using the parent classloader, which also loads interface A
                    - interface A is therefore loaded by two different classloaders -> classcastexception

                    It seems that the problem is not related to JBoss classloading, after all. The reason that the same war works in other servers, is that those servers do not have the same hibernate jars loaded by their "parent" classloaders.

                    So nice to finally understand what is going on here. Thanks a lot, I will sleep better now ;)

                    • 22. Re: Overriding universal classloader, JBoss 4.2.1GA
                      jaikiran

                       

                      It seems that the problem is not related to JBoss classloading, after all. The reason that the same war works in other servers, is that those servers do not have the same hibernate jars loaded by their "parent" classloaders.


                      That's right!

                      1 2 Previous Next