Hibernate Part I

Lochana Edirisinghe
3 min readMay 9, 2020

What is Hibernate?

Hibernate is one of the most popular Java Frameworks that simplify the development of Java application to interact with the database. It is an Object-relational mapping (ORM) tool. Hibernate also provides a reference implementation of Java API.

In Java Standard Edition, we are using JDBC to connect with the database. But in Java Enterprise Edition we are not going to use the only JDBC. It has introduced a new specification that is JPA (Java persistence API). So the implementation of JPA is provided by Hibernate. Hibernate JPA implementation wraps JDBC.

Native Hibernate has more features than JPA. But Native Hibernate is having all functions of JPA.

Major Advantages of Hibernate Framework

Hibernate is open-sourced and lightweight and performance are very fast. Also, it helps to generate independent queries. it provides facilities to create tables.

Advantages of using Hibernate over JDBC

Eliminates a lot of boiler plate code (When we are using JDBC we have to create connection properties for queries always.)

Supports inheritance, associations(relations), and collections.

HQL(Hibernate Query Language) is more object-oriented and closer to Java.

Hibernate implicitly provides transaction management

And also it wraps exceptions of JDBC and exception handling is not mandatory.

It supports cache memory.

Hibernate supports auto DDL operations.

What is an ORM tool?

A technique that converts the objects to table data of the database. An ORM tool helps in simplifying data creation, manipulation, and access.

Relations mapping

Relation mappings are one of the key features of Hibernate. It supports the same relations as the relational database model. Those are,

One to One

Many to One

Many to Many

Another important thing is you should remember to use annotations that belong to javax.persistence package instead of org.hibernate.annotations if you are implementing JPA in your project because of annotations that belong to org.hibernate.annotations are used for Native Hibernate.

Before using hibernate I think first of all it is better to read Hibernate documentation. Everything about Hibernate is there. Actually, there are no separate drivers for Hibernate JPA implementation and Native Hibernate. So if we are going to implement JPA, we have a responsibility to select correct annotations and methods according to JPA.

Guys, I hope you got some idea about what is Hibernate and hope to do how to bootstrap the Hibernate in my next story. Thank you!!

--

--