Create SessionFactory in Hibernate 4

We can create SessionFactory in Hibernate 4 latest version, viz Hibernate 4.3.8 till now using the StandardServiceRegistryBuilder class. In prior version of hibernate we build the SessionFactory something like this

But the class org.hibernate.cfg.Configuration.buildSessionFactory() is deprecated in latest version of Hibernate. For more information you can go to the Hibernate Deprecated List

Project Structure & Required Libraries:-

create sessionfactory in hibernate 4

Code to create SessionFactory in Hibernate 4.3.8:-

Example to test the SessionFactory:-


So We can create SessionFactory in Hibernate 4, when migrating from Hibernate 3 to Hibernate 4 without using the deprecated classes.

Leave a Reply

Your email address will not be published. Required fields are marked *