I am learning Hibernate in Java.
Since, to create a Session
, we have to use SessionFactory.openSession()
, and for creating SessionFactory
we use sessionFactory = config.buildSessionFactory(serviceRegistry);
What is the use of ServiceRegistry
in hibernate??
My code for creating SessionFactory
:
Configuration config = new Configuration();
config.addAnnotatedClass(user.class);
config.addAnnotatedClass(emp.class);
config.configure();
// Didn't understand the code below
Properties configProperties = config.getProperties();
ServiceRegistryBuilder serviceRegisteryBuilder = new ServiceRegistryBuilder();
ServiceRegistry serviceRegistry = serviceRegisteryBuilder.applySettings(configProperties).buildServiceRegistry();
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
A service registry is a database for the storage of data structures for application-level communication. It serves as a central location where app developers can register and find the schemas used for particular apps.
Most importantly, the SessionFactory in Hibernate is responsible for the creation of Session objects. The Hibernate Session provides methods such as save, delete and update, all of which are used to perform CRUD-based operations on the database to which the SessionFactory connects.
Q. What we can create more than one sessionFactory in Hibernate. Ans And Its true We can create.As in my app i am able to da same.
spi. SessionFactoryServiceRegistry is the 3rd standard Hibernate ServiceRegistry. Typically, its parent registry is the StandardServiceRegistry. SessionFactoryServiceRegistry is designed to hold Services which need access to the SessionFactory.
A ServiceRegistry, at its most basic, hosts and manages Services. Its contract is defined by the org.hibernate.service.ServiceRegistry interface. Currently Hibernate utilizes 3 different ServiceRegistry implementations forming a hierarchy.
EventListenerRegistry org.hibernate.event.service.spi.EventListenerRegistry is the big Service managed in the SessionFactoryServiceRegistry. This is the Service that manages and exposes all of Hibernate’s event listeners. A major use-case for Integrators is to alter the listener registry.
If doing custom listener registration, it is important to understand the org.hibernate.event.service.spi.DuplicationStrategy and its effect on registration. The basic idea is to tell Hibernate:
what makes a listener a duplicate
how to handle duplicate registrations (error, first wins, last wins)
StatisticsImplementor
org.hibernate.stat.spi.StatisticsImplementor is the SPI portion of the org.hibernate.stat.Statistics API. The collector portion, if you will.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With