SessionFactory in Hibernate4.x

SessionFactory in Hibernate4.x

In Hibernate 4.x version, cfg.buildSessionFactory() method was deprecated, because, to load hibernate software and to setup Hibernate environment it may take lot of time. To simplify Hibernate Software loading and to set up Hibernate Environment in simplified manner, Hibernate4.x version has included some booting features.

In Hibernate 4.x version, to create SessionFactory object we have to use the following steps.

1. Create Configuration Object with all configuration details

Configuration cfg = new Configuration();

2. Get all configuration details into Properties object

public Properties getProperties()


Properties p = cfg.getProperties();

3. Creating StandardServiceRegistryBuilder

StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

4. Get All configuration details from Properties object into StandardServiceRegistryBuilder object

public StandardServiceRegistryBuilder applySettings(Map m)


builder = builder.applySettings(p);

5. Create StandardServiceRegistry object

public StandardServiceRegistry build()


StandardServiceRegistry registry =;

6. Create SessionFactory object

public SessionFactory buildSessionFactory(StandardServiceRegistry registry)


Sessionfactory sf = cfg.buildSessionfactory(registry);
SessionFactory in Hibernate4.x
Scroll to top