Hibernate is a framework that helps to communicate with the database. It's also called an 'ORM' tool.
What is ORM?
ORM stands for Object Relational Mapping, where java objects are mapped with database tables, syncing one row with one record of java object is also called ORM
Hibernate helps us to write the persistence logic, a logic that is written to perform persistence operations like CRUD. To write persistence logic in java we have
Technology: JDBC
Framework: hibernate, spring data jpa
Even though we have JDBC what is the need for an ORM tool?
Limitations of JDBC
if we write persistence logic using JDBC then we have to write SQL queries by the following syntax, queries are specific to databases, which doesn't make it portable across multiple databases
If we use JDBC there's a lot of boilerplate code (code which repeats multiple times) for example load and register drive, establish a connection, create prepared statements, execute the query, process the resultset, handle the exception, closing the resource
JDBC throws only one exception which is SQLException and it's a checked exception so we need handling logic otherwise code would not compile. and we don't have a detailed hierarchy of exceptions related to a different problem.
JDBC ResultSet object is not serializable so we can't send it over the network
while closing the JDBC connection object we need to analyze the code a lot otherwise it would result in NullPointerException
we know that java is OOP based language so if we want to send a student object to the database it's not possible with JDBC because DB queries always accept the values not directly the object
JDBC doesn't have good support for transactional management
JDBC supports only positional parameters, it doesn't support named parameters which becomes difficult for the user to inject the values
to use JDBC strong knowledge of SQL is required
JDBC doesn't support versioning, and timestamp as an inbuilt feature
while developing persistence logic using JDBC we cant enjoy oops features like inheritance, polymorphism, and composition because JDBC doesn't allows object as input values in SQL queries
To overcome all above problems we use ORM tool
Hibernate is a tool implemented for JPA specifications given by sunmicrosystems
JPA->Java Persistence Api (set of rules and guidlines to implment ORM)