Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 36
Repository Pattern
The Repository pattern abstracts persistence behind an interface.
Course progress0%
Focus
2 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
The Repository pattern abstracts persistence behind an interface. Spring Data ships repositories you extend; for domain-driven systems you can also hand-write repositories that hide JPA entirely.
Informative example
ts
// Domain-driven flavour: hide JPA from the servicepublic interface OrderRepository {Optional<Order> byId(OrderId id);Order save(Order order);List<Order> activeFor(UserId userId);}// Adapter@Repository@RequiredArgsConstructorclass JpaOrderRepository implements OrderRepository {private final JpaOrderEntityRepository jpa;private final OrderMapper mapper;public Optional<Order> byId(OrderId id) {return jpa.findById(id.value()).map(mapper::toDomain);}// ...}
Ready to mark this lesson complete?Track your journey across the entire course.