Hibernate is an object-relational mapping (ORM) library for the Java language which is licensed under the open source GNU Lesser General Public License (LGPL), providing a framework for mapping an object-oriented domain model to a traditional relational database. Hibernate solves object-relational impedance mismatch problems by replacing direct persistence-related database accesses with high-level object handling functions. Hibernate is free software that is distributed under the GNU Lesser General Public License.

Hibernate’s primary feature is mapping from Java classes to database tables (and from Java data types to SQL data types). Hibernate also provides data query and retrieval facilities. It also generates the SQL calls and attempts to relieve the developer from manual result set handling and object conversion and keep the application portable to all supported SQL databases with little performance overhead.

Hibernate provides transparent persistence for Plain Old Java Objects (POJOs). The only strict requirement for a persistent class is a no-argument constructor, not necessarily public. Proper behavior in some applications also requires special attention to the equals() and hashCode() methods. Collections of data objects are typically stored in Java collection objects such as Set and List. Java generics, introduced in Java 5, are supported. Hibernate can be configured to lazy load associated collections. Lazy loading is the default as of Hibernate 3. Related objects can be configured to cascade operations from one to the other. For example, a parent such as an Album object can be configured to cascade its save and/or delete operation to its child Track objects. This can reduce development time and ensure referential integrity.

A dirty checking feature avoids unnecessary database write actions by performing SQL updates only on the modified fields of persistent objects. Hibernate provides an SQL inspired language called Hibernate Query Language (HQL) which allows SQL-like queries to be written against Hibernate’s data objects. Criteria Queries are provided as an object-oriented alternative to HQL.

Advantages of Hibernate

  • Hibernate is better then plain JDBC: You can use Hibernate which generates the SQL on the fly and then automatically executes the necessary SQL statements. This saves a lot of development and debugging time of the developer. Writing JDBC statement, setting the parameters, executing query and processing the result by hand is lot of work. Hibernate will save all tedious efforts.
  • Mapping of Domain object to relational database: Hibernate maps your domain object with the relational database. Now you can concentrate on your business logic rather than managing the data in database.
  •  Layered architecture: Hibernate is layers architecture and you can use the components as per your application need.
  • JPA Provider: Hibernate can work as JPA provider in JPA based applications.
  • Standard ORM: Hibernate is standard ORM solutions and it also supports JPA.
  • Database Independent: Hibernate is database independent and you can use any database of your choice.
  • Lazy object initialization. Hibernate can use runtime-generated proxies (CGLIB) or interception injected through bytecode instrumentation at build-time.
  • Caching Framework: There are many caching framework that works with Hibernate. You can use any one in your application to improve the  performance of your application.

Comments are closed.