JPA vs Spring Data

JPA

JPA is all about creating Objects which can map to the Database objects.

The application will use JPA specification to push or retrieve an object from the database, and underlying JPA implementations will take care of the low-level SQL queries. That is called Object Relational Mapping (ORM).

There are many JPA implementations like EclipseLink or Hibernate. With ORM, we use an API to query a particular database entity, and the result is provided in the form of a collection of java objects. Similarly, when we want to push data to the database, we need to populate Java objects and pass them to the API. The underlying ORM implementation is responsible for converting these API calls to the native SQL queries.

Spring Data JPA

Spring Data JPA is one of the many Spring Data projects, and it aims towards bringing consistency in accessing data for relational datastores. Many people consider Spring Data JPA is a JPA implementation. In reality, it is false. Spring Data JPA uses a default JPA Implementation called Hibernate. The default JPA implementation is configurable, and if we wish, we can use other implementations as well.

What is Spring Data JPA, if not a JPA Implementation? Speaking precisely, Spring Data JPA is an add-on for JPA. It provides a framework that works with JPA and provides a complete abstraction over the Data Access Layer. Spring Data JPA brings in the concept of JPA Repositories, a set of Interfaces that defines query methods. The Repository and Entity Bean represent the DAO layer in the application. No need to write native queries anymore. Sometimes we need to write queries or part of queries, but those are JQL queries and not native database queries.

Spring Data JPA is a sub-project of Spring Data and provides an abstraction over the Data Access Layer using Java Persistence API and ORM implementations like Hibernate.

Last updated