Prerequisites: Introduction of Hibernate Hibernate: Hibernate is a framework which is used to develop persistence logic which is independent of Database software. In JDBC to develop persistence logic we deal with primitive types. Whereas Hibernate framework we use Objects to develop persistence logic which are independent of database software. Hibernate Architecture: 
- Configuration is a class which is present in org.hibernate.cfg package. It activates Hibernate framework. It reads both configuration file and mapping files.
 
It activate Hibernate Framework Configuration cfg=new Configuration(); It read both cfg file and mapping files cfg.configure();
- It checks whether the config file is syntactically correct or not.
 - If the config file is not valid then it will throw an exception. If it is valid then it creates a meta-data in memory and returns the meta-data to object to represent the config file.
 
SessionFactory:
- SessionFactory is an Interface which is present in org.hibernate package and it is used to create Session Object.
 - It is immutable and thread-safe in nature.
 
buildSessionFactory() method gathers the meta-data which is in the cfg Object. From cfg object it takes the JDBC information and create a JDBC Connection. SessionFactory factory=cfg.buildSessionFactory();
Session:
- Session is an interface which is present in org.hibernate package. Session object is created based upon SessionFactory object i.e. factory.
 - It opens the Connection/Session with Database software through Hibernate Framework.
 - It is a light-weight object and it is not thread-safe.
 - Session object is used to perform CRUD operations.
 
Session session=factory.buildSession();
Transaction:
- Transaction object is used whenever we perform any operation and based upon that operation there is some change in database.
 - Transaction object is used to give the instruction to the database to make the changes that happen because of operation as a permanent by using commit() method.
 
Transaction tx=session.beginTransaction(); tx.commit();
Query:
- Query is an interface that present inside org.hibernate package.
 - A Query instance is obtained by calling Session.createQuery().
 - This interface exposes some extra functionality beyond that provided by Session.iterate() and Session.find():
- A particular page of the result set may be selected by calling setMaxResults(), setFirstResult().
 - Named query parameters may be used.
 
 
Criteria:
- Criteria is a simplified API for retrieving entities by composing Criterion objects.
 - The Session is a factory for Criteria. Criterion instances are usually obtained via the factory methods on Restrictions.
 
Flow of working during operation in Hibernate Framework : Suppose We want to insert an Object to the database. Here Object is nothing but persistence logic which we write on java program and create an object of that program. If we want to insert that object in the database or we want to retrieve the object from the database. Now the question is that how hibernate save the Object to the database or retrieve the object from the database. There are several layers through which Hibernate framework go to achieve the above task. Let us understand the layers/flow of Hibernate framework during performing operations: 
