Results 1 to 4 of 4

Thread: Spring 3 + hibernate 4 - ClassNotFoundException creating sessionFactory

Hybrid View

  1. #1
    Join Date
    Sep 2012
    Posts
    2

    Default Spring 3 + hibernate 4 - ClassNotFoundException creating sessionFactory

    Hi

    I have a maven web project using Spring version 3.1.2.RELEASE and Hibernate version 4.1.7.Final.

    On in initialisation the war throws an exception when creating the session factory bean:

    Code:
           java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.MetadataProvider
    According to my goolge searching MetadataProvider was deprecated and then deleted so there is no option unless I with to down grade to Hibernate 3! Just does not make sense to me.

    Full exception trace and context xml follow ( xxxxxxxxx replacing anything the boss might think sensitive )

    Code:
    SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/MetadataProvider
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:591)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
    	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
    	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
    	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
    	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:962)
    	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1603)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    	at java.lang.Thread.run(Thread.java:722)
    Caused by: java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/MetadataProvider
    	at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:277)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
    	... 26 more
    Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.MetadataProvider
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
    	... 29 more
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
    
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<!--  Local DB -->
    		<property name="url" value="jdbc:mysql://127.0.0.1:3306/xxxxx" />
    		<property name="username" value="xxxxx" />
    		<property name="password" value="xxxxx" />
    	</bean>
    
    
    	<!-- Hibernate session factory -->
     	<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    		<property name="dataSource">
    			<ref bean="dataSource"/>
    		</property>
    	 
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    				<prop key="hibernate.show_sql">false</prop>
    			</props>
    		</property>
    	 
    		<property name="mappingResources">
    			<list>
    				<value>/hibernate/formdata.hbm.xml</value>
    			</list>
    		</property>	
        </bean>
        
    	<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    	</bean>
    
    	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory"/>
    		</property>
    	</bean>
    
    	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    		<property name="dataSource">
    			<ref bean="dataSource"/>
    		</property>
    	</bean>	
    
        <bean id="wicketApplication" class="xxxxxxxxxxxxxxxxxxx">
    		<property name="jdbcTemplate">
    			<ref bean="jdbcTemplate"/>
    		</property>
    		<property name="hibernateTemplate">
    			<ref bean="hibernateTemplate"/>
    		</property>
    	</bean>
    </beans>

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    I strongly suggest you check your classpath as I suspect you have some older hibernate version (or related jar) somewhere in your classpath. (Check your server also).

    Another note don't use HibernateTemplate that isn't recommended anymore since hibernate 3.0.1 came out...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2012
    Posts
    2

    Default

    Thanks Marten

    Have cleaned up the classpath a deleted all unused web apps, tomcat lib directory now has only the original jars + Apache commons. Same with the jdk.

    Went over the pom and found an error which I thought might be causing the problem as it pulled in spring-test 3.0.2. I am now as shore as I can be without installing on a new machine that classpath is fine.

    Has made no difference

    Any particular reason for not using the Hibernate Template ?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default


    Any particular reason for not using the Hibernate Template ?
    Use the search as that question has been answered numerous times before, in short it doesn't give you any added benefit, as of Hibernate 3.0.1, anymore.

    As for your missing class some investigation shows that this file is part of hibernate-commons-annotations 4.0.1 which should automatically be retrieved by hibernate-entitymanager. So not sure what is wrong but I suspect your pom has either some wrong dependencies or you have some exclusions.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •