Spring Data JPA is a part of the larger Spring Data project that simplifies database interactions by reducing boilerplate code and providing an easy way to work with JPA (Java Persistence API). It is built on top of JPA and provides an abstraction layer to make database access more convenient in Spring Boot applications.
Spring Data JPA eliminates the need for writing complex DAO (Data Access Object) implementations by providing built-in methods for CRUD (Create, Read, Update, Delete) operations and query execution.
JpaRepository or CrudRepository.| Feature | JPA | Spring Data JPA |
|---|---|---|
| Definition | Java standard for ORM | Spring framework abstraction over JPA |
| Implementation | Requires a provider like Hibernate, EclipseLink | Uses JPA providers but adds convenience features |
| Configuration | Requires manual setup | Automatically configured in Spring Boot |
| Repositories | Uses EntityManager for queries |
Uses JpaRepository for easy CRUD operations |
| Query Writing | Uses JPQL/Native SQL | Supports derived queries, JPQL, and native queries |
| Boilerplate Code | Requires manual DAO implementation | Reduces boilerplate with predefined methods |
save(), findById(), findAll(), deleteById() are readily available.findByName(String name)).@Query annotation.findAll(Pageable pageable).