Introduction to Hibernate

Post by – Subhash Bhajankar

What is the problem that hibernate is trying to solve?

         Let’s take an example of simple class that you have in your application. Referring Image 1, we have Employee object in our java class which has six fields. In our running application We would have lots of such objects in memory, What if I restart my application ? Everything will be lost. So to overcome this problem and persist data inside my application i will save it in Database.

         As shown in below image every object in Java will be represented as single row. Here, class corresponds to table and object of class corresponds to row. This was something that we were been doing over the year (Off course before ORM Tool).

Normal approach to save data in Java is something like :

  1. Create JDBC Connection
  2. Connect Database
  3. Create SQL String dynamically by taking fields value one by one
  4. And also manage all transaction, Exception handling, rollback and commit
Necessity of Hibernate
1. Necessity of Hibernate

          So problem here is I have object here in java but I do not have objects here in Database  level. So for saving I have to convert each object’s data into SQL query. Also for retrieving we have to do opposite like convert Record set into object. So at the end we are repeating converting Object data to SQL and SQL result to object.

Wouldn’t it be great, if we have something, Some Tool, Some design pattern, which will take care of converting data between object and record?

If somehow, we try to create it by our own, We will face problems like :

  1. Mapping member variables to columns
  2. Mapping relationship
  3. Handling data types
  4. Managing changes to object state
  5. Offcource Performance also 🙂

To overcome all these problems we use ORM tool like Hibernate or Ibatis

ORM Tool
2. ORM Tool – Mapped Object and Table

Advantages of Hibernate :

  1. There are many advantages but I will list very few :
  2. One of Most common ORM accepted by Developers Community Worldwide
  3. Uses Java Persistance API (JPA)
  4. High Performance
  5. Reliability and Scalability
  6. Very easy to configure

This is my first post, so please share your thoughts.

Posted

in

by

Tags:


Related Posts

Comments

Leave a Reply

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

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading