Connect with me
What the heck is Hibernate!?
Hibernate simplifies Java persistence, but what exactly is it? This article breaks down Hibernate’s core concepts, how it manages database interactions, and why it’s a game-changer for Java development.

In this article we are going to talk about Hibernate. We will not be delving into any code and keep it stupid simple. In subsequent article series we will dig deeper into Hibernate where we code and see inner workings.
We are delving into the three introductory questions for Hibernate viz. What, Why and How.
What is Hibernate?
Hibernate is an Object-Relational Mapper based on Jakarta Persistence API specification.
Two big words🤯! Before answering our first question let’s simply and understand what these terms mean.
Hibernate is a program that is used to work with Relational databases inside of Java programs. Example of relational databases are: MySQL, PostgresSQL, MariaDB, SQLite etc.
Java program cannot execute SQL queries on their own and even when they can i.e. with things like JDBC (Java Database Connectivity) library the code gets a lot complex and tedious to maintain. So the industry came up with JPA and Hibernate ORM to solve this problem.
What is Object-Relational Map(per/ing) (ORM)?
An ORM is a concept where we try to map the relational data in databases to objects in a program.
As you may know, data in relational databases are stored in tables in row and column format.
Let’s say you have row with following data stored in a row, in some table of the database like this:
ID Name Age
1 Amrit 27
If we want to use this data in our program, specially in a language like Java where everything is represented with objects then this row column formatted data holds no meaning. This has to be converted this data to object format like POJO that Java understand.
With an ORM you can convert this row data into an object like POJO (Plain Old Java Object) to look like this:
Person {
Id: 1,
Name: Amrit,
Age: 27
}
When data is represented in an object format, it can then be used by our programs natively. And that’s what ORMs do.
What is Jakarta Persistence API specification?
Specification is a document telling you how to do a thing. You can call it a rulebook or receipe book to create certain things in a software program.
JPA was created by Oracle instructing everyone who wants to create their ORM to follow these specifications. Now, it is not mandatory to follow JPA specification but it is always good to follow one specification as it standardize practices throughout the industry.
For example, Spring JPA and Hibernate can work hand-in-hand because they follow same specifications.
JPA is a not final and can be built upon, which means, people can take the specifications and add more specifications and functionalities on top of it.
Hibernate follow JPA specification and add few more functionalities on top of it. We’ll discuss more in details once we delve deeper into the tutorials about JPA. But for now just know that Hibernate is built with JPA specification.
Now finally, we can conclude the question about “What is Hibernate” with this sentence:
Hibernate is a Java-based Object-Relational Mapping (ORM) framework that simplifies database interactions by mapping Java objects to relational database tables. It acts as an abstraction layer over databases, allowing developers to work with Java objects instead of SQL queries.
Now let’s see why the industry use Hibernate.
Why do we use Hibernate?
Java is already infamous for it’s complex syntax and patterns. If we add calling SQL queries inside of Java code, think of the overflow in complexity and failing regression!
To tackle this problem we got Hibernate as ORM for Java. We already saw what ORM is but to summarize the benefit we can say that Hibernate will help you in all these following things:

Hibernate is literally a magic wand for Java programs to deal with relational databases.
If you have not used ORMs before, one example how ORMs help is while creating schemas i.e. all tables, fields etc. in actual databases. You just have to specify the logical object structures in your native programming language and then when you run ORM program, it will automatically create required tables and fields in actual database.
Now let’s see how Hibernate solves the problems of databases in Java programs.
How Hibernate solves the problem of databases in Java?
There are many problems when it comes to dealing with relational databases in any programming language.
Here are some challenges we face while dealing with fetching data from databases:
Level of Granularity
Granularity refers to the level of detail in a dataset.
Many times, a table is associated with other tables to provide more details about a particular record.
For instance, consider an Employee table that contains an employee’s personal details, but the employee also belongs to a Department stored in a separate table. To retrieve the employee’s department name, we need to perform a join operation on the Department table.
This would mean that now we have to do two things in our Java code:
- Construct a complex SQL query.
- Re-use or Re-write this query at multiple places where required.
Inheritence
Relational databases do not support inheritance the way object-oriented programming does, hence native to Java, databases cannot help with OOP concepts.
But the need of the day is to have data structured in Objects rather than tables of rows and columns as Java don’t understand tabular data.
Association
In object-oriented programming, objects have bidirectional relationships.
For example, an Employee can have a reference to a Department, and the Department can also have a reference back to the Employee.
However, in relational databases, foreign key relationships are typically unidirectional by default. If a bidirectional relationship is needed, additional work is required to maintain consistency across tables.
Identity
In relational databases, each row is uniquely identified by a primary key.
However, when objects are loaded into memory in an application, their identity is determined by object references. This creates a challenge when two objects represent the same database row but are treated as different instances in memory.
Data Navigation
Writing manual SQL queries and calling them in the code can be very inefficient. Specially, if multiple queries are called on the same table. We may also face the issue of fetching unnecessary data leading to performance and memory overload.
Also, if a set of data is being called multiple times frequently, it also makes sense to have mechanism like caching and lazy loading which when taken over falls on the shoulders of developers to maintain and fix.
Now that we understand the problems, we can clearly see that there is a need of an abstraction layer on top of databases working for our Java Code to help us better deal with databases and persistence of data.
Summary
In this article we discussed the basics of Hibernate from a very layman viewpoint answering three important introductory questions — What, Why and How. In subsequent articles we will dig deeper into the inner workings of Hibernate. Take a look at the sneakpeak below.

Subscribe to my newsletter today!