JAVA: Understanding Hibernate

ELMASLOUHY Mouaad
2 min readDec 20, 2021

--

Hibernate is an open source ORM (Object Relational Mapping) type solution which facilitates the development of the persistence layer of an application. Hibernate therefore allows you to represent a database in Java objects and vice versa.

What is ORM ?

Object-Relational Mapping (ORM) is a technique that lets you query and manipulate data from a database using an object-oriented paradigm.

from www.javaguides.net

The Configuration to use Hibernate

from www.jmdoudoux.fr

Example:

from www.jmdoudoux.fr

The use of Hibernate

To use Hibernate in the code, it is necessary to perform several operations:

1. creating an instance of the class
2. creating an instance of the SessionFactory class
3. creation of an instance of the Session class which will allow you to use Hibernate services.

Storing data

if we want to store an object of a Person class in a database :

  1. first thing to do is adding @Entity to the class.
  2. write this code after the previous in the main class.

Fetching data

--

--

ELMASLOUHY Mouaad

Computer science Engineer Student, A lover of everything that urges the mind to work hard such as Quantum Physics, General Medicine, Personal dev…