Tuesday, October 13, 2009

Why to use hibernate when other persistence mechanism are there??

Well there are many reasons for hibernate to be used in place of others.

I list some of the most important reasons.

1:)Hibernate provides the Object Relation Mapping(ORM):
Well it has always been a concern for the java developers,they wanted a tool that can provide a proper ORM.Through ORM,the classes(POJO) are directly mapped to the tables and the object state is persisted as the row in that table.

2:)Hibernate provides Transparent and Automated persistence:
Transparent means that hibernate allows the class (that is to be persisted) to be free from any special implementation.Meaning that you don't have to implement any interface or extends to any class.Hence the developers don't have to consider anything about the persistence.

Automated is something that allows the programmers to be free from the low level database implements.Hence developers don't have to write low level queries,they are generated by hibernate(it uses its own query language called HQL).

3:)Hibernate supports Dirty Checking:
This makes sure that any changes that are made to the object will also be reflected in the database.Hence you don't have to again explicitly save the object.

4:)Hibernate support Fine-grained domain models:
This is the most important requirement for rich domain model.This basically allows you to have more classes than the tables.

Example in a design for a User entity we may have address,street no,city etc. as attributes,but wait there is a problem with this:what if a User has a home address,office address.Well you can have soo maany columns for each of them.

But in hibernate you can have a separate class called Address with all of the above as attributes.This basically reduces the time taken to execute the queries.

5:)Hibernate also supports the dynamic manipulation of meta-data:
Using this you can update the database schema even at the run time.

6:)Hibernate offers platform independence:
With this you can even work on legacy systems with out any problems.

7:)Hibernate supports polymorphic queries:
Well this feature of Hibernate is quite unique.This basically allows to retrieve the DB row and store it in super class reference.

Well the list continues.I must say that its really worth using Hibernate in application development.But its always better to use it in big application.

No comments:

Post a Comment