What is Spring Data JPA?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Spring Boot development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

Spring Data JPA is a Spring Data module that drastically simplifies working with JPA (Java Persistence API) databases by eliminating boilerplate repository code. JpaRepository: extends CrudRepository and PagingAndSortingRepository. Provides: save(), findById(), findAll(), delete(), count(), existsById(), findAll(Pageable), findAll(Sort). public interface UserRepository extends JpaRepository<User, Long> { // Query derived from method name: List<User> findByEmailAndStatus(String email, String status); List<User> findByAgeBetween(int min, int max); Optional<User> findByEmail(String email); long countByStatus(String status); // Custom JPQL query: @Query("SELECT u FROM User u WHERE u.name LIKE %:name% AND u.active = true") List<User> searchActive(@Param("name") String name); // Native SQL query: @Query(value = "SELECT * FROM users WHERE MATCH(bio) AGAINST(:term)", nativeQuery = true) List<User> fullTextSearch(@Param("term") String term); @Modifying @Query("UPDATE User u SET u.status = :status WHERE u.id = :id") void updateStatus(@Param("id") Long id, @Param("status") String status); }. @Entity: marks a class as JPA entity (database table). @Id, @GeneratedValue: primary key and generation strategy. Pagination: userRepository.findAll(PageRequest.of(0, 10, Sort.by("createdAt").descending())). Auditing: @EntityListeners(AuditingEntityListener.class) with @CreatedDate, @LastModifiedDate — auto-populate timestamps.

Pro Tip

This topic has Spring Boot-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.