Are you a Java Developer? Are you fed up of writing and configuring so much for even a simple select query? You no longer have to do this all. Yes, you heard it right. You no longer have to write all those boilerplate codes if you use Spring Data JPA.

What is Spring Data JPA?

Spring Data JPA is a library/framework which is a part of the Spring Data family. Spring Data JPA makes it easy to implement JPA based repositories. This framework has enhanced support for JPA based data access layers.

Spring Data JPA helps you focus on business logic instead of technical complexity and boilerplate code.

Is JPA and Spring Data JPA the same?

The answer is no.

JPA is a specification that standardizes the way Java Objects are mapped to a relational database system. Being just a specification, JPA consists of a set of interfaces, like EntityManagerFactory, EntityManager, and annotations that help you map a Java entity object to a database table.

There are several JPA providers, like HIbernate, EclipseLink, or Open JPA which you can use.

Spring Data JPA is a JPA data access abstraction. Just like JPA, Spring Data JPA cannot work without a JPA provider. It generates JPA queries on your behalf through method name conventions.

JPA handles most of the complexity of JDBC based database access and ORMs(Object Relational Mappings). On top of that, Spring Data JPA reduces the amount of boilerplate code required by JPA.

Why was Spring Data JPA developed?

Implementing a data access layer of an application using JPA or JDBC is cumbersome. Too much boilerplate code to execute simple queries, to perform pagination and auditing.

To avoid all these, Spring Data JPA was developed. Spring Data JPA improves the implementation of data access layers by reducing the effort that is actually needed.

Repositories available in Spring Data JPA

There are 3 repository interfaces that every user of Spring Data JPA should know.

1.CRUD Repository

 This interface defines a repository that offers standard Create, Read, Update, and Delete operations.

2.Paging & Sorting Repository 

  This interface extends the CRUD repository; Adds findAll method that enables you to sort the result and retrieve it in a paginated way.

3.JPA Repository

 This interface adds JPA specific methods like flush() etc.

Advantages of Spring Data JPA

1.No code repositories

2.Reduced boilerplate code

3.Easy to use

4.Generated Queries

This is just an introduction to Spring Data JPA. Stay tuned for more information on Spring Data JPA.

Thank you.