Spring Data JPA Repositories
Design a small subsystem that relies on Spring Data JPA Repositories. Outline components, data flow, failure modes, and metrics.
Answers use simple, clear English.
Audio N/AQuick interview answer
Use Spring Data JPA Repositories as the core idea. Example shape: findByEmailIgnoreCaseAndActiveTrue(String email) generates query at startup..
Detailed answer
Use Spring Data JPA Repositories as the core idea. Example shape: findByEmailIgnoreCaseAndActiveTrue(String email) generates query at startup.. Watch for: Derived query names explode; N+1 if fetch graphs missing.. Measure success via latency/error/saturation. Core: Interface extending JpaRepository<T,ID> gets CRUD + query methods from method names. @Query for JPQL/native; Pageable for pagination. Real-time example: findByEmailIgnoreCaseAndActiveTrue(String email) generates query at startup. Pros: Minimal boilerplate; pagination and sorting built-in. Cons: Derived query names explode; N+1 if fetch graphs missing. Common mistakes: Long derived method names unreadable; missing @Transactional on service layer writes. Best practices: Use @EntityGraph or JOIN FETCH for associations; DTO projections for reads. Audience level: Senior.
Full explanation
Interface extending JpaRepository<T,ID> gets CRUD + query methods from method names. @Query for JPQL/native; Pageable for pagination.
Real example & use case
findByEmailIgnoreCaseAndActiveTrue(String email) generates query at startup.
Pros & cons
Pros: Minimal boilerplate; pagination and sorting built-in. Cons: Derived query names explode; N+1 if fetch graphs missing.
Common mistakes
Long derived method names unreadable; missing @Transactional on service layer writes.
Best practices
Use @EntityGraph or JOIN FETCH for associations; DTO projections for reads.
Follow-up questions
Only answered follow-ups are shown — click to open with full answers