Your Ad Here

Thursday, June 2, 2011

Why Hibernate ?

Hibernate, is Open Source Persistence technology and an Object-Relational Mapping (ORM) solution for JAVA. It is powerful, high performance O/R persistence and query engine. Working with Relational Database is complicated task with JDBC because there is mismatch between how data is represented in objects versus relational
database. So with JDBC, developer has to write code to map an object model's data representation to a relational data model and its corresponding database schema. At the other end Hibernate is flexible and powerful ORM solution to map Java classes to database tables.

Hibernate key features:

1) Hibernate 3.0 provides three type of facilities to query in database, via Hibernate Query Language(HQL), via Criteria Query and native SQL.
2) It also provides full support for projection/aggregation and subselects.
3) Hibernate can be used to develop/package and distribute the applications for free as it is under LGPL(GNU Lesser General Public License).
4) Mapping of Java objects with database tables and vice versa is called Transparent Persistence. It provides transparent persistence and developer does not need to write code explicitly to map database tables rows to application objects during communicating with Relational Databases. Using JDBC this need to be write manually with some lines of code.
5) Using JDBC, if there is any table / column / datbase change then developer need to write / modify the code many places. As table changed or database changed then it’s essential to change object structure as well as to change code written to map table-to-object/object-to-table.
Hibernate provides this mapping itself. The actual mapping between tables and application objects is done in XML files. If there is change in Database or in any table then the only need to change XML file properties.
6) Hibernate supports Automatic Versioning and Time Stamping, By database versioning one can be assured that the changes done by one person is not being roll
backed by another one unintentionally. Hibernate enables developer to define version type field to application, due to this defined field Hibernate updates version field of database table every time relational tuple is updated in form of Java class object to that table. So if two users retrieve same tuple and then modify it and one user save this modified tuple to database, version is automatically updated for this tuple by Hibernate. When other user tries to save updated tuple to database then it does not allow to save it because this user does not has updated data. In JDBC there is no check that always every user has updated data. This check has to be added by the developer.
7) Maintenance Cost reduses with Hibernate, With JDBC, it is developer’s responsibility to handle JDBC result set and convert it to Java objects
through code to use this persistent data in application. So with JDBC, mapping between Java objects and database tables is done manually. Hibernate reduces lines of code by maintaining object-table mapping itself and returns result to application in form of Java objects. It relieves programmer from manual handling of persistent data, hence reducing the development time and maintenance cost.


Main Disadvantages of Hibernate:

1) There will be a learning curve.
2) Hibernate is not for Data centric applications. For Instance if there is an application which used to use DB procedures and business logic at DB level not at Java object level then Its better not to choose hibernate, use JDBC instead.

No comments:

Post a Comment