Hibernate – Introduction and Overview

Last modified date

Hibernate is an Open Source Framework which is widely used in enterprises application develop Java Applications. Hibernate is licensed under GNU Lesser General Public License (LGPL), it is free to download.

Prerequisites to learn Hibernate

It is recommended we must have good understanding of JDBC (Java Database Connectivity) technology and also we must have knowledge of any one of the RDBMS database for example like (MySQL, Oracle, H2 Database etc.) will be helpful.

Before going in details we must understand why Hibernate has efficient features comparing with JDBC and what are the advantages and disadvantage of JDBC.

Advantage and Disadvantage of JDBC

Advantages Disadvantages
Works great and smooth in executing SQL queries Could be complex for heavy processing projects
Can handle large amount of data Large programming overhead
Works great for small applications eg : J2SE applications Encapsulation is not possible
It is easy to learn It is hard to implement MVC concept


What is ORM?

ORM stands for Object Relational Mapping, if you consider any RDBMS the data in it will represent in a tabular form whereas Object Oriented languages like Java and C# represents in Objects.

Just imagine we are creating a project using JDBC with a RDBMS, in this process we will go with anyone specific Database (like : Oracle, MySQL etc ) and develop the project, but later due to some database compatibility we may change the database. In this case we must rewrite the Database queries depending on the new Database.

Where in Hibernate you no need to depend on any specific Database, Hibernate has its own HQL (Hibernate Query Language) Object Oriented version of SQL, which takes care of molding itself with any Database even if you change to another database at project development time.


Advantage of Using Hibernate in Java Project:

Open Source : Hibernate is licensed under GNU Lesser General Public License (LGPL), it is free to download and use.

CRUD Operations : CURD (Create, Update, Read, Delete) operations are very smooth comparing with JDBC in Hibernate. Once we map the Java objects with Hibernate, table creation is automatic and Update,Select, Delete are so easy with few lines of code writing. Almost 80% of Code writing is reduced comparing with regular JDBC operation and query writings.

Fast Performance Cache: Hibernate Framework is in build with first level cache and second level cache, so that the performance is high.

Handle Complex Queries : Hibernate takes care of writing complex join queries very simple and easy.