Saturday 10 May 2014

what is hibernate

Hibernate is an ORM tool.ORM means

object relational mapping
. It is used to persist data in database.

There are lot of feature that have been added in hibernate over the years .
But when it was started its primarily goal was to persist data in the database.
All the feature have been covered in next few post.
Let’s assume we have a class named as UserClass as follow-

UserTable

Now lets there are five objects of above user class.
To save data of these five objects there must be a table as shown below-

User Table

UserDataBaseTable

Now to save data we create Jdbc connection and pullup data from objects and write sql query for insertion .

The problem that hibernate solve are following:-

Mapping member variable to column:-While inserting data to table we map the member variable to column of table.
If we use Hibernate then all this mapping is done by hibernate.

Mapping Relationship:-Let’s there are two table user and address to save data about user and his and his address.
Now in this case address is dependent upon user.To accomplish this we use primary key and foreign key concept.
If we use hibernate then all these relationship are taken care by hibernate.

Handling Data type:-  some of databases do not allow some particuler data type to be saved.
E.g :Mysql do not allow to save Boolean data type.
So programmer need to manually convert  these data types in some another like for true programmer can use Y
and for false programmer can use N of char type.
When we use hibernate then  this all is handle by hibernate not by programmer.

Managing Object State:- If we need to create object back from the data in the table then we pullup the record
and cast them in object data member variable. Now after creating objects processing is done on the object .
So the value have been changed.To accommodate these changes in data base we need to update
the data in the database.
Hibernate simplify it.
 

what is hibernate




mapping

Conclusion:-On the application side there are object but on database side there are records.
So hinbernate is an ORM tool map the objects of application to the records of database.