In the previous example we have seen, there is an 'Employee' class which is exactly same as a table named 'EMPLOYEE.'
Now, let's assume we have created a java application that creates an 'Employee' object and populates it.
Now, let us see the above diagram. And as we can see, there is something called Persistent Object(You can consider the 'Employee' object). This Persistent Object is the only object, we create in java. Then, this Persistent Object(Say 'Employee') is passed to the Hibernate Framework using some interfaces.
Then Hibernate loads this object to the database. So, it is the Persistent Object(Say 'Employee') which resides in our Java Application and the Hibernate Framework.
i.e. Say there is a java class Employee :
Similarly in the database there is a table EMPLOYEE :
In order to link these two, Hibernate uses a mapping file, where you can specify which field of the java class should be linked with what field in the table. Hibernate takes the help of this Mapping file to link the object and the table.
Usually Hibernate uses JDBC to connect to the database. So, in order to know which JDBC driver to use, Hibernate takes the help of a configuration file. We can specify the details about the JDBC driver, the DB(i.e. Oracle or DB2 or PostGres) in the configuration file and Hibernate will pick the right driver and DB based on it.
On top of the Hierarchy, there is the Configuration class which manages the configuration file and initializes the necessary classes needed to run Hibernate. So, whenever Hibernate starts, the configuration file is initialized.
Next comes the SessionFactory class and as the name suggests, it is a factory of Sessions.
i.e. Whenever you ask for a Session object, the SessionFactory is going to deliver a Session object for you.
A Session object is used to deal with a particular transaction.
i.e. Say there is an Employee object and a Student object. Both needs to be saved to the same database. Now, you need to make sure that different sessions should be created for Employee and Student object so that their data don't collide with each other. It's same as the tigers and the lions are put in separate cages so that they don't fight each other.