Spring Data JPA Repositories
Compare Spring Data JPA Repositories with a common alternative (angle 1). How do you decide in a design review?
Answers use simple, clear English.
Quick interview answer
Baseline: Interface extending JpaRepository<T,ID> gets CRUD + query methods from method names. @Query for JPQL/native; Pageable for pagination.
Detailed answer
Baseline: Interface extending JpaRepository<T,ID> gets CRUD + query methods from method names. @Query for JPQL/native; Pageable for pagination. Prefer when pros dominate: Minimal boilerplate; pagination and sorting built-in.. Avoid when: Derived query names explode; N+1 if fetch graphs missing.. 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: Fresher.
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