Saturday, June 4, 2016

Why use Hibernate and what is JPA ???

Hibernate is an object-relational mapping framework for the Java language. It provides a framework for mapping an object-oriented domain model to a relational database.
There are some key points about Hibernate

  • It is an ORM (Object Relational Mapping) framework.
  • It implements JPA (Java Persistence API).
    JPA is a set of standards that have been described for implement any persistence in software.



There is a main drawback in persisting data through an application. Let’s think of a scenario that we use a relational database for persisting data and java as the programming language. In our application we need to store details of our users So there will be a user class in code.











And there will be corresponding table in the database.









So when data persisting in to database through our application there are several things need to be done.

  1. Make connection to database.
  2. Pull up all the data fields from the object.
  3. Create a SQL query with data to insert into database.
  4. Finally execute the SQL query.
So the conversion between Java objects and SQL queries has to be done every time when retrieve and persist data.

In this approach we have problems with Mapping member variables to columns, mapping relationships, Handling data types and managing changes to object states. So it is better to use a framework that follows standards so that we don’t have to deal with above problems over and over again. So hibernate is that kind of life saving framework for java developers. Though Hibernate is popular there are other frameworks as well that do the same object relational mapping.

No comments:

Post a Comment

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...