Hibernate over JDBC

In this article, we are going to discuss Hibernate.
First of all, what is Hibernate? Hibernate is an ORM framework.
Now what is ORM (Object Relational mapping)? Still, if it's not making sense then let us explain to you about it.
ORM acts as a middle layer between Java Objects and relational database tables. That is it takes the ownership of converting Java objects to database tables and vice versa.

Let's discuss some benefits of hibernate over JDBC

  • It provides a caching mechanism to reduce DB hit count. Let's suppose you have a banking application that uses simple JDBC, here you want to check your account profile. So click on your profile icon and it will use a select query to fetch data from DB and will show you on GUI. you close it and repeat the same thing 10 times. What I want to emphasize here is that 10 times you hit db to retrieve these details. And as we already know, fetching data from DB is a costly operation. Using Hibernate we can avoid such things.
  • Hibernate provides sessions and transaction mechanisms to handle DB CRUD operations efficiently, which is nontrivial in the case of JDBC. Hibernate also ensures that transactions follow ACID (Atomicity, Consistency, Isolation, Durability) properties while handling DB operations.
  • Hibernate helps developers to focus more on the Object Oriented side rather than DB handling side. All the manual DB side tasks like writing SQL queries, and table creation are taken care of by Hibernate. Also, as we already mentioned that it will be responsible to convert objects into tables, therefore no more table SQL queries need to be written by developers. Also, if developers want they can write their custom queries. So it's totally not blocking developers to write SQL queries but helping them to focus more on business logic.
  • Provide mechanisms to create relation mapping between objects/tables like one-to-one, one-to-many, many-to-one, and many-to-many using OOP paradigms like inheritance, and composition.
  • Hibernate using Hibernate Validator provides a way to validate data before storing it in the db by putting constraints on the field of Object (columns in the table). constraints like not null, min value, max value, etc.
  • Using Hibernate, Developers do not need to worry about different dialects of relational DB. As the writing of SQL query is taken care of by hibernate, developers only need to focus on writing business logic. Also, Hibernate has its own query language HQL (Hibernate Query Language), developers can use it to write any custom queries and Hibernate will convert this to the native SQL language of the used DB. It means the same HQL will work with Oracle SQL DB and Microsoft SQL DB as well although they have different dialects.




Note : Please comment below for any improvement , suggestions, regarding any wrong information present in this article. We will improve it so that only right information available in this article.




Comments