elibraryportal Logo

Hibernate OverView

Hibernate is an ORM framework.

ORM stand for Object Relational Mapping it is a technique to map data of Object Domain into data of Relational Domain. In each Application, Application developers need to persist data into databases and need to fetch persistent data from databases. Java provides JDBC API for this task.

→ Main functionality of an ORM Framework is to persist objects and their relations into the database on behalf of Application Developers. For this ORM Frameworks require configuration & mapping information which can be provided in the form of XML or Annotations.

Hibernate framework simplifies the development of java application to interact with the database. Hibernate is an open source, lightweight, ORM (Object Relational Mapping) tool.

Fig1:-

Hibernate OverView1


Fig2:-

Hibernate OverView2

Commonly used classes and interfaces exposed by Hibernate for Application Developers –

1) Configuration

→ Configuration object is used by the Hibernate to store Configuration Information in object form. Configuration Information represents data required by Hibernate to connect to a DB & information of classes that are to be managed by Hibernate.

2) SessionFactory

→ It is a factory class which is used by Application Developer to create session. Apart from this, it can also be used to manage 2nd level caching of persistent object.

3) Session

→ This is the main interface with which Application Developer interact. This interface provides methods for persisting object, creating transactions & query object.For each user a different session is created.

4) Transaction

→ This interface is used by Application Developer to transact execution of queries.

5) Query

→ This interface is used by the Application Developer to execute HQL (Hibernate Query Language) Queries. HQL is an Object based version of SQL used by Hibernate.


Steps required to persist objects using Hibernate :-

First Step

The persistent class objects of which are to be persisted is to be created. A persistent class has following characteristics

  • It has a unique identifier which is used by Hibernate to uniquely identify objects.
  • It provides getter & setter methods for all its properties.

Second Step

A mapping file need to be created to specify information of database tables in which data of objects is to be persisted.

Third Step

A configuration file that contains database properties & references of mapping files need to be created.

Fourth Step

A configuration object is created.

Fifth Step

Using the configuration object a SessionFactory is obtained.

Sixth Step

Using the SessionFactory, Session object is obtained.

Seventh Step

Using the Session, objects are persisted.

Fig:-

Hibernate OverView3