Home Hibernate Hibernate4 Hibernate 4 AnnotationSessionFactoryBean

Related Tutorials


 
 

Share on Google+Share on Google+

Hibernate 4 AnnotationSessionFactoryBean

Advertisement
Learn about Hibernate4 AnnotationSessionFactoryBean and understand what is the correct solution.

How to use AnnotationSessionFactoryBean in Hibernate 4? Can it be used?

In this tutorial we are going to explain you about Hibernate4 AnnotationSessionFactoryBean which is not available in Hibernate 4. As a part of migration process of your Hibernate 3 application to Hibernate 4 you have to make necessary changes in your configuration files. This tutorial explains you how to update from Hibernate 3 to Hibernate 4.

If you use the following code in your Hibernate 4 application it will give you the error. Code used in Spring 3:

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

Application may give the following error:

nested exception is java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider;

So, you have to use the org.springframework.orm.hibernate4.LocalSessionFactoryBean instead of AnnotationSessionFactoryBean. So this change is required as a process of migration to Hibernate 4.

In the Hibernate 4 the CacheProvider-related interfaces and classes has been removed. Now the RegionFactory related cache interfaces are available for secondary level caching.

Here is the complete code of using the LocalSessionFactoryBean instead of AnnotationSessionFactoryBean in Hibernate 4 applications:

<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

You can include the above code in your application configuration file.

More tutorials of Hibernate 4:

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 27, 2013

Related Tutorials

Discuss: Hibernate 4 AnnotationSessionFactoryBean  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com