Prior to Hibernate 4
The way of implementation of session connection is only with SessionFactory.
Example:
Configuration cfg=new Configuration();
Configuration cfg=cfg.configure(“mysql.cfg.xml”);
SessionFactory sf=cfg1.buildSessionFactory();
Hibernate 4.0,4.1,4.2
It changes with the concept of ServiceRegistry and the way of implementation is with ServiceRegistry & SessionFactory.
Example:
Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(
configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
Hibernate 4.3
ServiceRegistryBuilder() also deprecated and replaced with StandardServiceRegistryBuilder().
Example:
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
configuration.getProperties()).build();
My questions are:
- What is the difference b/w SessionFactory & ServiceRegistry ?
- Why Concept of ServiceRegistry is required ?
- What is the advantage of introduce ServiceRegistry over SessionFactory ?
- What is the difference b/w ServiceRegistryBuilder() & StandardServiceRegistryBuilder() ?