Using an ORM to access the database
Accessing a database performing SQL requests can be performant and can work for simple applications. However, when the application becomes more complex and the database schema grows, it can be interesting using an Object-Relational Mapping (ORM) framework to access the database using an Object-Oriented Programming (OOP) layer. Probably, the most popular ORM framework in Java is Hibernate, and Spring Data JPA uses Hibernate as its default Java Persistence API (JPA) implementation.
In this recipe, we will create entity classes that can be mapped to the database schema, and we’ll interact with the database without writing a single line of SQL.
Getting ready
You will need a PostgreSQL database for this recipe. You can reuse the database created in the Connecting your application to PostgreSQL recipe. If you haven’t completed that recipe yet, you can complete the first two steps of that recipe to create the database.