-
1. Re: Classloader nightmare and ClassCastException. Isolatio
jaikiran Apr 8, 2008 3:20 AM (in response to tnine)Which version of Hibernate do you use? How have you packaged the hibernate jar in the EAR (where is it placed)? Please post the complete exception stacktrace that you see. Also, when Hibernate session factory gets built, it prints out the version of Hibernate being used. Something like:
12:47:51,714 INFO [Version] Hibernate EntityManager 3.2.1.GA 12:47:51,761 INFO [Version] Hibernate Annotations 3.2.1.GA 12:47:51,776 INFO [Environment] Hibernate 3.2.4.sp1
What do you see in your case? -
2. Re: Classloader nightmare and ClassCastException. Isolatio
tnine Apr 8, 2008 3:27 AM (in response to tnine)I'm using the following version of Hibernate and Spring
Hibernate 3.2.6.ga
Hibernate Annotations 3.3.0.ga
Spring Framework 2.0.5
Here's the stacktrace19:24:05,422 ERROR [JMSContainerInvoker] Exception in JMSCI message listener javax.ejb.TransactionRolledbackLocalException: Could not instantiate bean at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:262) at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:350) at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181) at org.jboss.ejb.plugins.RunAsSecurityInterceptor.invoke(RunAsSecurityInterceptor.java:109) at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205) at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:136) at org.jboss.ejb.MessageDrivenContainer.internalInvoke(MessageDrivenContainer.java:402) at org.jboss.ejb.Container.invoke(Container.java:954) at org.jboss.ejb.plugins.jms.JMSContainerInvoker.invoke(JMSContainerInvoker.java:987) at org.jboss.ejb.plugins.jms.JMSContainerInvoker$MessageListenerImpl.onMessage(JMSContainerInvoker.java:1287) at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:266) at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:905) at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170) at org.jboss.mq.SpySession.run(SpySession.java:323) at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:194) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:748) at java.lang.Thread.run(Thread.java:613) Caused by: javax.ejb.EJBException: Could not instantiate bean at org.jboss.ejb.plugins.AbstractInstancePool.get(AbstractInstancePool.java:206) at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(MessageDrivenInstanceInterceptor.java:87) at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:63) at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:121) ... 16 more Caused by: javax.ejb.EJBException: org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [statementsMdb], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'statementsMdb' defined in URL [jar:file:/Users/toddnine/work/servers/jboss-4.0.5.GA/server/pefcu/tmp/deploy/tmp59925statements-app-1.0.0-beta-4-SNAPSHOT.ear-contents/mdb-1.0.0-beta-4-SNAPSHOT.jar!/beanRefContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: java.lang.ClassCastException@bfefb9 at org.jboss.ejb.MessageDrivenEnterpriseContext.<init>(MessageDrivenEnterpriseContext.java:94) at org.jboss.ejb.plugins.MessageDrivenInstancePool.create(MessageDrivenInstancePool.java:50) at org.jboss.ejb.plugins.AbstractInstancePool.get(AbstractInstancePool.java:184) ... 19 more Caused by: org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [statementsMdb], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'statementsMdb' defined in URL [jar:file:/Users/toddnine/work/servers/jboss-4.0.5.GA/server/pefcu/tmp/deploy/tmp59925statements-app-1.0.0-beta-4-SNAPSHOT.ear-contents/mdb-1.0.0-beta-4-SNAPSHOT.jar!/beanRefContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: java.lang.ClassCastException@bfefb9 at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:405) at org.springframework.ejb.support.AbstractEnterpriseBean.loadBeanFactory(AbstractEnterpriseBean.java:116) at org.springframework.ejb.support.AbstractMessageDrivenBean.ejbCreate(AbstractMessageDrivenBean.java:78) at sun.reflect.GeneratedMethodAccessor85.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.jboss.ejb.MessageDrivenEnterpriseContext.<init>(MessageDrivenEnterpriseContext.java:82) ... 21 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'statementsMdb' defined in URL [jar:file:/Users/toddnine/work/servers/jboss-4.0.5.GA/server/pefcu/tmp/deploy/tmp59925statements-app-1.0.0-beta-4-SNAPSHOT.ear-contents/mdb-1.0.0-beta-4-SNAPSHOT.jar!/beanRefContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: java.lang.ClassCastException@bfefb9 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:451) 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.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:733) at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:395) ... 27 more Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: java.lang.ClassCastException@bfefb9 at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:96) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:186) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:800) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:720) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:387) ... 33 more Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@bfefb9 at sun.reflect.GeneratedConstructorAccessor39.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:85) ... 38 more
Perhaps I missed the point, but I thought that scoped classloaders with override would allow me to use any version I choose. Is that not correct? Coincidentally, it works with Hibernate 3.2.0.ga and Annotations 3.2.0.ga.
Thanks,
Todd -
3. Re: Classloader nightmare and ClassCastException. Isolatio
tnine Apr 8, 2008 3:40 AM (in response to tnine)Also, just an FYI, removing the hibernate-annotations jar from my server's lib directory fixes the issue. However this doesn't seem to be a very good solution.
-
4. Re: Classloader nightmare and ClassCastException. Isolatio
jaikiran Apr 8, 2008 4:04 AM (in response to tnine)
Hibernate 3.2.6.ga
Hibernate Annotations 3.3.0.ga
Spring Framework 2.0.5Coincidentally, it works with Hibernate 3.2.0.ga and Annotations 3.2.0.ga.
The exception stacktrace that you posted does not show anything related to hibernate. But going by what you are explaining, about the issue, i guess you will have to package hibernate-search.jar (the version is 3.0.0.GA or 3.0.1GA) and lucene-core-2.2.0.jar (along with the hibernate-annotations 3.3.0 GA and the hibernate jar 3.2.6GA) in your application. See the hibernate version compatibilty matrix for these jars at http://www.hibernate.org/6.html
See this thread for more details http://www.jboss.com/index.html?module=bb&op=viewtopic&t=120419&postdays=0&postorder=asc&start=0. The first page of the thread is probably not much of interest, the second and third page talk about similar issue as this. -
5. Re: Classloader nightmare and ClassCastException. Isolatio
tnine Apr 8, 2008 4:19 AM (in response to tnine)That's very strange. I'll try packaging the search up tomorrow. I'm not sure how this will solve my issue, since both of my hibernate dependencies are in maven, and transitive dependencies are be included. I still don't understand why I'm having this issue in the first place. If my integration tests run fine in POJO mode with my dependencies defined by maven, obviously I have all the required class files in my Jars. If they're in my jars, then JBoss should be loading the class files in my jars first, not the ones on the server lib. It seems it's not loading the classes from my EAR first, but rather the parent classloader, which would cause the ClassCastExceptions and errors with versions in Hibernate.
-
6. Re: Classloader nightmare and ClassCastException. Isolatio
tnine Apr 8, 2008 10:26 PM (in response to tnine)Well, I found a work around by following the formula from the previous post. I was getting the following exception at the bottom of my trace. I accidentally posted the wrong section in my earlier post
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' defined in class path resource [statements-mdb.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.validator.event.ValidateEventListener at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1175) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:428) 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) ... 59 more Caused by: java.lang.ClassCastException: org.hibernate.validator.event.ValidateEventListener at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:783) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1202) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172) ... 65 more
So, I went digging for what project the class org.hibernate.validator.event.ValidateEventListener is a member of. Its used in the hibernate validator project. I added the hibernate-validator jar version 3.3.0.ga to my MDB's dependencies. As soon as I deployed with this additional jar, my issue was solved. I'm still not sure why Hibernate was trying to load this class, since I don't need it to perform my integration testing. Hopefully this will help someone else out!