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();
cfg.configure();

2. Get all configuration details into Properties object

public Properties getProperties()

E.g

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)

E.g

builder = builder.applySettings(p);

5. Create StandardServiceRegistry object

public StandardServiceRegistry build()

E.g

StandardServiceRegistry registry = builder.build();

6. Create SessionFactory object

public SessionFactory buildSessionFactory(StandardServiceRegistry registry)

E.g

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