0 Replies Latest reply on Oct 15, 2007 12:07 PM by Janne Mattila

    JBoss 4.2.1GA, Hibernate classes included in war

    Janne Mattila Newbie

      I am having classloading issues when I include hibernate JARs in my war. jars have to be included in the war because the application needs to be able to select hibernate version freely.

      My application uses hibernate to implement JPA.

      I have tried to override universal classloader with jboss-web.xml:

      <jboss-web>
      <context-root>/</context-root>

      <class-loading java2ClassLoadingCompliance="false">
      <loader-repository>
      org.myapp:loader=hibernatetestclassloader
      <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
      </loader-repository>
      </class-loading>

      </jboss-web>

      But no success. the error I am experiencing is

      java.lang.ClassCastException: org.hibernate.search.event.FullTextIndexEventListener

      I have created a simple test application to recreate the problem.



      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.f
      actory.support.DefaultListableBeanFactory@18845af: defi
      ning beans [transactionManager,userDao,urlMapping,listUsersController,viewResolver,org.springframewo
      rk.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.springfr
      amework.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: Er
      ror creating bean with name 'transactionManager' define
      d in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'en
      tityManagerFactory' 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; nest
      ed exception is java.lang.ClassCastException: org.hiber
      nate.search.event.FullTextIndexEventListener
      Caused by:
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionM
      anager' defined in ServletContext resource [/WEB-INF/di
      spatcher-servlet.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean pr
      operty 'entityManagerFactory'; nested exception is org.
      springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFac
      tory' defined in ServletContext resource [/WEB-INF/disp
      atcher-servlet.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastExcept
      ion: org.hibernate.search.event.FullTextIndexEventListe
      ner
      Caused by:
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManage
      rFactory' defined in ServletContext resource [/WEB-INF/
      dispatcher-servlet.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastEx
      ception: org.hibernate.search.event.FullTextIndexEventL
      istener
      Caused by:
      java.lang.ClassCastException: org.hibernate.search.event.FullTextIndexEventListener
      at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.jav
      a:856)
      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)

      at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersi
      stence.java:127)
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityMana
      gerFactory(LocalContainerEntityManagerFactoryBean.java:
      218)
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractE
      ntityManagerFactoryBean.java:251)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMe
      thods(AbstractAutowireCapableBeanFactory.java:1201)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBe
      an(AbstractAutowireCapableBeanFactory.java:1171)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(A
      bstractAutowireCapableBeanFactory.java:425)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFac
      tory.java:251)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(Defau
      ltSingletonBeanRegistry.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(Be
      anDefinitionValueResolver.java:261)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNeces
      sary(BeanDefinitionValueResolver.java:109)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropert
      yValues(AbstractAutowireCapableBeanFactory.java:1099)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean
      (AbstractAutowireCapableBeanFactory.java:861)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(A
      bstractAutowireCapableBeanFactory.java:421)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFac
      tory.java:251)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(Defau
      ltSingletonBeanRegistry.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(Be
      anDefinitionValueResolver.java:261)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNeces
      sary(BeanDefinitionValueResolver.java:109)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropert
      yValues(AbstractAutowireCapableBeanFactory.java:1099)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean
      (AbstractAutowireCapableBeanFactory.java:861)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(A
      bstractAutowireCapableBeanFactory.java:421)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFac
      tory.java:251)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(Defau
      ltSingletonBeanRegistry.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.preInstantiateSingle
      tons(DefaultListableBeanFactory.java:287)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicatio
      nContext.java:352)
      at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkSer
      vlet.java:331)
      at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServl
      et.java:265)
      at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:23
      5)
      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(ModelMBeanOperationInterce
      ptor.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(SubDeployerInt
      erceptorSupport.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(ModelMBeanOperationInterce
      ptor.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(AbstractDeplo
      ymentScanner.java:263)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploym
      entScanner.java:274)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeployme
      ntScanner.java:225)
      18:31:25,296 ERROR [[/]] StandardWrapper.Throwable
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springfr
      amework.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: Er
      ror creating bean with name 'transactionManager' define
      d in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'en
      tityManagerFactory' 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; nest
      ed exception is java.lang.ClassCastException: org.hiber
      nate.search.event.FullTextIndexEventListener
      Caused by:



      Java sources for the classes:

      http://rapidshare.com/files/62742397/java.zip.html