JAVA: Understanding Hibernate
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.
The Configuration to use Hibernate
Example:
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 :
- first thing to do is adding @Entity to the class.
- write this code after the previous in the main class.