Hibernate is an open source ORM (Object Relational Mapping) framework. Hibernate simplifies the development of java application to interact with the database. It reside in persistence tier in classic modern tiered based architecture. Hibernate in turns maps as follows:
- database table to java POJO class
- database row to object
- database column to java property.
History of Hibernate framework
Initially, it was developed by Gaving King later contributed to opensource community, nowadays, maintained by RedHat.
1. Why Hibernate framework?
In initial development days we do not have any ORM tool , few company having own proprietary tool or framework to use. The different band level (developer, manager, CXO) using Hibernate for different perspective.
As Developer: It’s niche technology and enjoyed and feed proud using Hibernate.
Project Manager: Sometimes, PM feels proud that his team member using latest technology so that team member will stay longer duration because of latest tech stacks and development pace would be faster by just mapping of table to Java class.
2. Architecture of Hibernate
Typically, there are 4 layers in Hibernate architecture:
1) Java application layer,
2) Hibernate framework layer,
3) Backend API layer and
4) Database layer.
3. Advantage of Hibernate
There are many advantages of Hibernate Framework which I mentioned below, if you have used properly.
- Opensource: Hibernate framework is open source under the LGPL license.
- Lightweight: Hibernate framework is lightweight ORM framework.
- Fast performance: The performance of hibernate framework is fast , if you have used relationship mapping is good. There are many reason for fastness there are many parameter how you measure its fastness. in short few cache is internally used in hibernate framework. There are two types of cache in hibernate framework first level cache and second level cache. First level cache is enabled by default.
- Database Independent query: HQL (Hibernate Query Language) is the object-oriented version of SQL. It generates the database independent queries. So you don’t need to write database specific queries. Before Hibernate, If database is changed for the project, we need to change the SQL query as well that leads to the maintenance problem.
- Auto Generation of Schema: Hibernate framework provides the facility to create the tables of the database automatically. So there is no need to create tables in the database manually.
- Simplifies complex join: Developers are playing around object most of the time , so Hibernate provide us to build join on objects on which relationship need to established. To pull hierarchal data or to pull form multiple tables is easy in Hibernate framework.
- Provides query statistics and database status: Hibernate supports Query cache and provide statistics about query and database status.
4. Disadvantage of Hibernate
I could not found any disadvantage in Hibernate specially usability perspective. But when you go for comparative study then obviously found few.
- Batch: Usually Hibernate not suitable for batch type of application.
- Overhead: When you get habitual to use JDBC on that point of time you feel why should we add one extra layer. but adding one extra layer is not a pain using that appropriately is the game.
- if Relationship not proper: In any one of project, if your entity relationship is not established well then you can find your life hell. I observed sometimes in my life, my colleague removed Hibernate from his project by saying that its slow but strongly recommend your entity relationship should be well established relationship else you have to remove in production. Its all about how you are going to use this, and how much you know i.e. how much depth you are in Hibernate.
5. Available Projects under Hibernate
The following are the different projects or Modules under the umbrella of Hibernate mega project.
- Hibernate ORM : it provide domain model persistence for relational databases
- Hibernate Search:: Hibernate provide full-text search for your domain model
- Hibernate Validator: : Hibernate provide annotation based constraints for your domain model which you can use for validations.
- Hibernate OGN:This project is for domain model persistence for NoSQL datastores
- Hibernate Tool: This project provide us a Command line tools and IDE plugins for your Hibernate usages
- Hibernate Others: We like the symmetry, everything else is here
At glance, we can say we should use Hibernate, specially I enjoy by using Hibernate in more than 10 project which are very reliable projects. We strongly recommend to use based on the use case to use case, not for all.