Master java skills

Architecture

Hibernate architecture can be understood from the below diagram. It is a high level diagram.

As we can see in the above diagram, Hibernate framework consists of two important files called Mapping file and Configuration file.

Mapping file – This file contains information about how java class would be mapped to a database table.

Configuration file – This file contains information about connection details required to connect to a database.

Let’s dive a little deeper into its architecture.

Building blocks of hibernate API.

Below objects are the building blocks of any hibernate application. It is really necessary to understand them to have a good understanding of how hibernate framwork functions.

  1. SessionFactory – As the name suggests, it is a factory object that creates session objects. There can be one SessionFactory object per database in any application. That means if an application works with multiple database, there would be one SessionFactory per database. It is a thread-safe object and can be accessed by multiple threads in the application simultaneously.
  2. Session – This objects represents a session between java and database communication. It is a short lived object. This holds first level cahce in hibernate.
  3. Transaction – This represents atomic unit of work. That means a sequence of operations which are considered as a single unit. A transaction is considered complete when all the operations under it are complete. A transaction follows ACID rules. A – Atomicity, C – Consistency, I – Isolation, D – Durability
  4. Connection Provider – This is a factory of jdbc connections. This interface is not intended to be exposed to the application. It is internally used by Hibernate to obtain connections.