Overview
In entire web applications, the DAO layer usually consists of a lot of boilerplate code that can be simplified.
Benefits of Simplification
- Decrease in the number of layers that we need to define and maintain
- Consistency of data access patterns and consistency of configuration
Spring Data JPA framework takes this simplification one step forward and makes it possible to remove the DAO implementations entirely. The interface of the DAO is now the only artifact that we need to explicitly define.
How It Works
For this, a DAO interface needs to extend the JPA specific Repository interface:
JpaRepository
or its super interface CrudRepository
- This enables Spring Data to find this interface and automatically create an implementation for it
📚 Spring Data JPA Links (Bookmark them!)
- API Docs: https://docs.spring.io/spring-data/data-jpa/docs/current/api/
- Reference Docs: https://docs.spring.io/spring-data/jpa/docs/current-SNAPSHOT/reference/html/#reference
🏗️ Repository Interface Hierarchy
1. Root Interface
org.springframework.data.repository.Repository<T,ID>
- Type: Marker interface
- T: Type of the entity