Introduction to Hibernate

Hibernate Logo
Hibernate is a framework which is used to interact with Database Servers. We use Hibernate framework as an alternative to JDBC. Apart from Hibernate there are many tools available in the market which are responsible to interact with Database Servers. The following are some of them:
  • JDO
  • JPA
  • Toplink
  • SDO    etc...,
Comarision with JDBC:
  • In JDBC once if the connection is established with the database server, and if we do not close it, then we get a problem saying maximum number of cursors exceeded. To resolve this problem we use connection pool. If we use framework like hibernate internally they uses connection pool.
  • In Real time projects we always divide the projects into multiple parts. Some programs are responsible to retrieve data from DBServers and some are responsible to display them. But in JDBC ResultSet object(rs) is not transferable. This problem can be resolved by using Hibernate or JPA frameworks.
  • In JDBC every method throws an unreported exception, due to this the JDBC code becomes huge. But in Hibernate no method throws an unreported exception. 
  • If we develop a project to communicate with DBServer using JDBC, we need to take care of queries. This is because some queries are specific to some databases, they will not work for all the DBServers. This problem is resolved in Hibernate by introducing HQL queries. HQL queries interact with any DBServers.
  • In real time projects, we always create tables with Primary keys, by using JDBC we have to write huge amount of code to generate the value for Primary key. But in Hibernate, its internal code takes care of generating primary key values.
  • In JDBC we have write the code to take care of Transactions, In Hibernate, the internal code will take care of Transactions. 
The following is the architecture of Hibernate:

Architecture of Hibernate
Fig2: Architecture of Hibernate.
Hibernate is an ORM(Object Relational Mapping) tool. In market we have so many ORM frameworks like: JPA(Java Persistence API), JDO(Java Data Object), SDO, Toplink etc..., In Database Servers we represent the data in the form of Relational tables. The representation of Relational data(Tables) in the form of Objects is called as Object Relational Mapping. 
ORM representation
Fig: ORM representation

                                           
                    

No comments:

Post a Comment