Saturday 4 November 2017

Story of HIBERNATE

Hello Friends,

Today I am going to explain Hibernate, Just think about JDBC what it is?You know right?
Hibernate is "New Avatar" of JDBC but it does not mean that Hibernate is implementation of JDBC.
just wait for Story, will explain......

Developer like me don't want to write more code, Like in JDBC don't want to write try, catch and finally block and then close the database connection i am so lazy haan :) hahahaha....just kidding.. :

I get irritated  :-

1. By repeating the same lines of code over and over again in Application for fetching data from database.
2. If want to migrate from one database to another.
3. When want to implement OOPS with JDBC code (JDBC donest support OOPS features)
4. To create association between two tables or more than two tables.

Now i am very much happy to share it that there is an ORM tool called HIBERNATE that we can use to overcome this.

Hibernate is a tool which is called ORM.
So before start Hibernate who should have knowledge of ORM.


ORM- Object Relational  Mapping, in which we map the Java object with relational database tables.

Suppose if we take a Class Employee and there are three instance variables so there is one configuration file (anyName.hbm.xml) in which we write the mapping code for hibernate to create database with tables.
We can say that it's like magic to create automatic database in Hibernate. 
But yes it's not by default .we will have to write  code for this.its up to  you, if you want automatic tables creation or not.

I will show example with details.

what is Hibernate?

It is ORM tool in which we map the database tables with Java Class Instance variables.

Hibernate supports inheritance , Association and Collections which JDBC does not support.

Theere are many features of Hibernate like 

1) Automatic Creation of relational database tables in Hibernate we can create database with tables by adding one property in configuration file (hibernate.cfg.xml).

2)Caching mechanism -Chaching mechanism is BOON for us, means there is no need to hit database again and again for same data in one session.
There are two type of Cache in Hibernate.
First Level Cache(by default Cache) & Second Level Cache(Query level Cache).I will explain this topic further.


3)HQL -Hibernate Query Language is a way to write the database query in Hibernate, HQL is object oriented which JDBC doesn't support.
It is database independent.
Support during or after development if clients ask to change database then it will be very easy in Hibernate which is very  tedious task in JDBC.

4)No need of Try Catch- In JDBC we face many challenges regarding Compile time and Runtime time Exceptions and waste a lot of time with extra codes to catch many exceptions which we don't do in Hibernate so Hibernate is best alternative of JDBC.
But yes it does not means that we can't not SQL in Hibernate,yes we can use but if we have great features like HQL which is object oriented then what's the need of JDBC.

We have learned about many features of Hibernate,.