Pages Navigation Menu

Coding is much easier than you think

Hibernate advantages and disadvantages


 

Advantages of using Hibernate

 

  • Traditionally Programmers need to write functions that convert the object to query and result set to object. To overcome these difficulties, Hibernate provides a mechanism to maps Java classes to database tables and from Java data types to SQL data types and relieve the developer from 95% of common data persistence related programming tasks. Read more..
  • Database independent – Hibernate has its own query language, i.e Hibernate Query Language(HQL) which is independent of database. HQL is an object-oriented extension to SQL, So we no need to write code specific to database.
  • No knowledge of SQL is needed. For example saveOrUpdate(entityObject) takes care of insertion in case of Hibernate.
  • Takes care of dependencies between tables and does join queries.
  • Query tuning is not required in Hibernate as it is automatically achieved by using Criteria queries
  • Hibernate supports first level cache by default. This reduces the number of round trips between application and database and hence increases performance.
  • Hibernate supports Inheritance – In hibernate if we save the derived class object, then its base class object will also be stored into the database.
  • Hibernate supports relationships like One-To-Many,One-To-One, Many-To-Many-to-Many, Many-To-One
  • Hibernate supports Collections like List,Set,Map
  • Hibernate has capability to generate primary keys automatically while we are storing the records into database.
  • Maintains transactions commit and rollback.
  • Maintains database connection pool.
  • Hibernate does not require an application server to operate.

 

Supported Databases:

 
Hibernate supports almost all the major RDBMS. Following is list of few of the database engines supported by Hibernate.

  • HSQL Database Engine
  • DB2/NT
  • MySQL
  • PostgreSQL
  • FrontBase
  • Oracle
  • Microsoft SQL Server Database
  • Sybase SQL Server
  • Informix Dynamic Server

 

Disadvantages of hibernate

  • If it is a small project with few tables(< 10 tables) , then there is no need for a ORM framework. In such case a normal JDBC is enough.
  • Hibernate has a performance cost as it adds a layer over jdbc. Also with Hibernate lot of table configuration information (hbm or annotations) is read at start up adding to the start up time of your application.
  • Not suitable for Batch processing– It advisable to use pure JDBC for batch processing.