Hibernate Architecture

  • Facebook
  • Google
  • LinkedIn
  • Twitter

Below diagram describes the high level architecture of hibernate:

Hibernate Architecture

Hibernate architecture is a three tier architecture in which a Java application is interfaced with the back end database using the hibernate as a middle layer. The important thing in mapping the object to the database objects is to write the configuration file for hibernate. Hibernate is written in Java and is configured using two types of files hibernate.cfg.xml and hibernate.hbm.xml.

Hibernate reads the XML configuration file for getting the database connection, string, password, database dialect and location of mapping files.

The hibernate.hbm.xml configuration file that is mapping description file. This file helps hibernate to map data between specific Java class and database tables.

Below are the element of hibernate architecture

Session Factory

The SessionFactory is a factory of session and client of ConnectionProvider and a thread safe, immutable cache of compiled mappings for a single database. A factory for org.hibernate.Session instances. It holds second level cache (optional) of data. The org.hibernate.SessionFactory interface provides factory method to get the object of Session.

Session

The session object provides an interface between the application and data stored in the database. It is a object and wraps the JDBC connection and a factory of Transaction, Query and Criteria. It holds a first-level cache of data. The Session interface provides methods to insert, update and delete the object. It also provides factory methods for Transaction, Query and Criteria.

Transaction

The transaction object specifies the atomic unit of work. The Transaction interface provides methods for transaction management. Transactions in Hibernate are handled by the transaction manager and transaction (from JDBC or JTA).

ConnectionProvider

It is a factory of JDBC connections. It abstracts the application from underlying javax.sql.DataSource or java.sql.DriverManager.TransactionFactory

Query Object

Query objects use SQL or Hibernate Query Language (HQL) string to retrieve data from the database and create objects. A Query instance is used to bind query parameters, limit the number of results returned by the query, and finally to execute the query.

Criteria Object

Criteria object are used to create and execute object oriented criteria queries to retrieve objects.

      Advertisements