Introduction to Hibernate Framework

Hibernate was started in 2001 by Gavin King (who created Jboss server) with his colleagues from Cirrus Technologies as an alternative to using EJB2-style entity beans. Its original goal was to provide better persistence capabilities than provided by EJB2 by simplifying the complexities and supplementing missing features.

Objective of Hibernate:  It provides features to develop data access layer of an Enterprise application.

Limitations of JDBC API:

  • Portability: Developer needs to write different SQL statements for Database’s.
  • Developer needs good knowledge on Database.
  • Exception handling: Developer need to handle the SQLException (checked exception), using try/catch blocks or throws.
  • Caching need to be implemented manually.
  • JDBC stores data in the form of text. Not as an objects.

Alternative to JDBC is ORM.

What is ORM?

  • Object Relational Mapping.
  • An ORM framework maps the object’s data to relational data.

What is Hibernate?

  • It is a open source ORM framework
  • It will not force the developer to extend/interface any class/interface.
  • It can run without server. No need of any server to run Hibernate programs.

What are the advantages of Hibernate?

  • Hibernate persists/saves java objects into database.
  • We can switch the database easily with Hibernate. It is Database vendor independent.
  • We have only Un-checked exceptions in Hibernate. No need of using try/catch or throws. Hibernate internally uses translator to convert checked exception to Un-checked.
  • It provides Connection pooling.
  • It supports Inheritance, Association and Collections.
  • It provides HQL which is Database vendor independent.
  • It provides automatic primary key generation.
  • It provides Caching, Lazy loading, pagination.
  • It supports annotations and JPA.

What are the disadvantages are of hibernate?

  • Slower than JDBC: Hibernate generates lot of SQL statements in runtime.
  • It’s very easy to learn JDBC. Hibernate is having lots of API to learn.
  • Not recommended if your project is having fewer tables.
  • Not recommended for batch procession. Use JDBC for batch processing.

Posted in hibernate and tagged , .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.