Hibernate architecture
We will see Hibernate architecture in 2 views
1) High level view of Hibernate Architecture
2) Detailed view of Hibernate Architecture
Hibernate architecture shows configuration details and various objects involved in each layer
Hibernate uses Java API like JDBC API,Java Transaction API(JTA) and Java Naming and directory Interface(JNDI)
The below figure illustrates High Level View of Hibernate Architecture
The below figure illustrates Detailed View of Hibernate Architecture
Let’s discuss various elements involved in Hibernate architecture
It represents a configuration required to use the hibernate , which could be properties file or XML file.
Configuration
The Configuration object is usually created once during application initialization.
The Configuration object uses the configuration details from the configuration file to get connected to a database.
A Configuration object is used to create a SessionFactory.
Object Relational Mapping
The mapping between Java POJO class and the database tables is provided using either XML or annotation.
SessionFactory
It is the factory for the session objects.
It is thread safe and immutable object representing the mappings for a single database.
It can hold the second level cache in hibernate
Session
It’s a single-threaded, short-lived object which acts as a bridge between Java application and Hibernate.
It wraps a JDBC connection and is a factory for Transaction.
Session holds a mandatory first-level cache of persistent objects
Transient objects
Instances of persistent classes which are not currently associated with a Session
Persistent objects
They are associated with Session and Once the Session is closed, they will be detached and free to use in any application layer
Query
Query objects use Native SQL or Hibernate Query Language (HQL) to retrieve data from the database.
A Query instance is used to bind query parameters such as number of results returned by the query.
We can obtain the query object from the session using session.createQuery()
Criteria
The org.hibernate.Criteria is used to retrieve the entities based on some criteria like getting all employees by specific age or specific date of joining etc.
We can get the Criteria from the Session.
TransactionFactory
A factory for Transaction instances,It is not exposed to the application and it’s optional.
Transaction
single-threaded, short-lived object used by the application to specify atomic units of work
We can obtain the transaction from the Session object.
ConnectionProvider
It’s a pool of JDBC connections
Simple and clearly explained
very nice tutorial. Each and every topic is explained very nicely.
you have kept so much effort to keep each topic in simple way to understand.
thank you very much sir.
Thank you Gopal !!