Announcement Announcement Module
Collapse
No announcement yet.
configurationClass must be assingable to org.hibernate.cfg.Configuration? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • configurationClass must be assingable to org.hibernate.cfg.Configuration?

    Trying to jump to annotations within Spring-Hibernate and getting the following error. I've read through previous threads and followed various tutorials but it all comes back to this error. Have also tried splitting the config into two files (the beans and a specified hibernate.cfg.xml) and still get the exact same error. Ideas?

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [persistence.hibernate.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: configurationClass must be assignable to [org.hibernate.cfg.Configuration]
    Caused by: 
    org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: configurationClass must be assignable to [org.hibernate.cfg.Configuration]
    Caused by: 
    java.lang.IllegalArgumentException: configurationClass must be assignable to [org.hibernate.cfg.Configuration]
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.setConfigurationClass(LocalSessionFactoryBean.java:212)
    	at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean.setConfigurationClass(AnnotationSessionFactoryBean.java:73)
    	at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean.<init>(AnnotationSessionFactoryBean.java:65)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:82)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:59)
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:52)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:639)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:625)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:287)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
    	at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3854)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4359)
    	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(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	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(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	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(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	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(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	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(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	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)
    Metadata:
    Code:
    	<!-- setup hibernate session factory -->				
    	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    		<property name="dataSource">
    			<ref bean="dataSource" />
    		</property>
    		<property  name="annotatedClasses">
    			<list>
        			<value>com.cisco.txbu.admin.data.Company</value>
        		</list>
      		</property>   
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
    				<prop key="hibernate.show_sql">true</prop>
    				<prop key="hibernate.generate_statistics">true</prop>
    				<prop key="hibernate.hbm2ddl.auto">update</prop>
    				
    				<!--
    				<prop key="hibernate.connection.pool_size">5</prop>
    				<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
                	<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
                	<prop key="hibernate.hibernate.cache.use_query_cache">true</prop>
                	-->
    
    			</props>
    		</property>
    	
    	</bean>

  • #2
    I had exactly the same problem when deploying a new hibernate/spring project to jboss. The deployed war file contained the hibernate core jars but didn't contain the annotations jar. I was specifying an AnnotationsConfig in spring which was loading the AnnotationConfig class from jboss' libraries. It then tested compatibility with the Configuration class loaded from hibernate core libs in my war. Different classloaders meant they were deemed incompatible.

    The solution was to include the annotations jars in my war file too.
    Last edited by thatmikewilliams; Dec 2nd, 2007, 06:29 AM.

    Comment


    • #3
      Once again this seems to be a classpath error. You probably got Hibernate deployed to multiple classloaders.

      Joerg

      Comment


      • #4
        Actually, the problem has been resolved but it had nothing to do with class path. Hibernate annotations 3.3.0 kills off a method Spring needs when setting up the config. Worked when we changed the dependency back to annotations 3.2.1.

        Comment


        • #5
          But that can not be the reason for the error mentioned above. The stacktrace clearly shows that. In AnnotationSessionFactoryBean.setConfigurationClass () following check is made:

          Code:
          if (configurationClass == null || !AnnotationConfiguration.class.isAssignableFrom(configurationClass)) {
          	throw new IllegalArgumentException(
          			"AnnotationSessionFactoryBean only supports AnnotationConfiguration or subclasses");
          }
          This check is passed. Immediately after this the following check in LocalSessionFactoryBean.setConfigurationClass() is made:

          Code:
          if (configurationClass == null || !Configuration.class.isAssignableFrom(configurationClass)) {
          	throw new IllegalArgumentException(
          			"configurationClass must be assignable to [org.hibernate.cfg.Configuration]");
          }
          And on this one you fail. How can you pass the more strict one (AnnotationConfiguration extends Configuration) but fail for the other one? Only for the one reason that Configuration is loaded by a different classloader than AnnotationConfiguration.

          Joerg

          Comment


          • #6
            In my case it was definitely a classpath problem. AnnotationConfiguration was loaded from jboss classpath, Configuration was loaded from my application's classpath. Fixing my application classpath to include the annotations jar solved it.

            Setup: jboss 4.2.2, spring 2.5, hibernate 3.2.5 core, annotations 3.3.0

            Comment

            Working...
            X