Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ClassNotFoundException: org.hibernate.cache.CacheProvider exception while integrating spring and hiberate

I am getting the below exception when I am trying to test the spring and hibernate integration.

Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.CacheProvider
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 18 more

application-context

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:annotation-config/>

<!-- Datasource beans -->

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  <property name="url"  value="jdbc:mysql://localhost:3306/sterlingschema" />
  <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  <property name="username" value="root" />
  <property name="password" value="root" />
</bean>

<!--  Hibernate Template session factory bean -->
 <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
       <props>
           <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
           <prop key="show_sql">true</prop>
           <prop key="hibernate.hbm2ddl.auto">update</prop>
       </props>
    </property>

    <property name="mappingResources">
       <list>
           <value>/org/droidaceapps/domain/users.hbm.xml</value>
       </list>
     </property>

</bean> 

<!--  Hibernate template beans -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
      <property name="sessionFactory" ref="sessionFactory"></property>
</bean>


<!--  DAO beans -->

<bean id="userDAO"  class="org.droidaceapps.dao.UserDAOImpl">
  <property name="hibernateTemplate" ref="hibernateTemplate" />
</bean>

<!--  Service beans -->

<bean id="userService"  class="org.droidaceapps.services.UserServiceImpl">
    <property name="userDAO" ref="userDAO" />
</bean> 

When I googled on this problem some said that we should be using springframework.orm.hibernate4 instead of springframework.orm.hibernate3. I did that. But still I am getting the same exception.

Can someone help me in Identifying what am I missing here.

Thanks

like image 327
droidsites Avatar asked Aug 15 '12 22:08

droidsites


2 Answers

Note : org.hibernate.cache.Provider was removed in the change from Hibernate 3 to Hibernate 4.

If you use hibernate 3, you may get the java.lang.ClassNotFoundException: org.hibernate.cache.CacheProvider. If you change to hibernate 4, you will not get that, but you firstly should add hibernate4.jar and spring-orm.jar.

like image 141
cameron Avatar answered Nov 29 '22 03:11

cameron


It sounds liken you are missing hibernate dependency in your project set up:

Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.CacheProvider

Try downloading hibernate-core.jar and add to your project classpath.

If you use Maven, simply add the following dependency to your project's pom.xml:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>${hibernate.version}</version>
</dependency>

Hope that helps.

like image 26
yorkw Avatar answered Nov 29 '22 01:11

yorkw