Pages

Thursday, September 13, 2012

hibernate no class found exception

Exception in thread "main" java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider;at java.lang.Class.getDeclaredFields0(Native Method)at java.lang.Class.privateGetDeclaredFields(Class.java:2308)

The above exception usually happens when we use hibernate4 with spring 3. look at the below sping xml bean declaration.

<bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="mad.springnhibernate.model" />
<property name="hibernateProperties">
<props><prop key="dialect">org.hibernate.dialect.MySQLDialect</prop></props>
</property>

</bean>

The error happens because of the class of the bean. If you are using hibernate4 then there is no such class. If you are using hibernate4 then you need to change it to org.springframework.orm.hibernate4.LocalSessionFactoryBean. The the code will stop giving you the above exception.


No comments:

Post a Comment