2- Configure Spring Boot & JPA

For the
Spring Boot to be able to connect to a database, you need to configure in the
applications.properties file. You can use any database with which you are familiar. Below are 4 configurations corresponding to 4 most common kinds of databases (
MySQL, Oracle, SQL Server, PostGres).

In practice, let's create a empty schema named
"mydatabase". The
JPA will create tables corresponding to the
Entities included in the application.

3- Spring Data JPA (Quick Start)

In the
JPA, each
Entity class will correspond to one table in the database. There are very many tables in the database, therefore, there will be a lot of
entity classes. You frequently have to work with
Entities, and write
DAO classes (
Data Access Object) to manipulate data through these
Entities. This is actually a boring job.

OK, I will tell you why it is boring. Let's imagine that you have 2 tables in the database such as
EMPLOYEE &
DEPARTMENT, and you have 2 corresponding
Entity classes such as
Employee & Department.

To manipulate with
Employee, you write a
DAO class including similar methods as follows:

Employee findById(Long id)

List<Employee> findAll()

List<Employee> findByName(String likeName)

.....

Certainly, to manipulate with the
Department, you also do the same thing and if
Entities are too many, it will take you so much time.

Spring Data JPA is a library of
Spring. According to the rule of the
Spring Data JPA, you just need to define an extended interface-
Repository<T,ID> interface, and declare methods to manipulate with the data of this
Entity. The
Spring Data JPA will create a class that implements that interface for you.

EmployeeRepository Interface extends
CrudRepository<Employee, Long> interface.It has methods to manipulate with the
Employee entity. The
Spring Data JPA will automatically create a class that implements this interface at the time of running the application.