Back to blog Backend Interview

50 Spring data JPA Real Interview Questions Asked in MNC

34 min readBackend Interview

Spring Data JPA – Core & Conceptual Questions

1. What is Spring Data JPA and how is it different from plain JPA?

2. What is JPA and why is it used in Java applications?

3. What are the advantages of using Spring Data JPA?

4. What are the key interfaces in Spring Data JPA (CrudRepository, JpaRepository, PagingAndSortingRepository)?

5. What is the Repository pattern?

6. What is the role of @Repository annotation?

7. How does the method name query derivation mechanism work in Spring Data JPA?

8. What is the difference between CrudRepository and JpaRepository?

9. What is an Entity in JPA?

10. Explain EntityManager and its responsibilities.

11. What is the Persistence Context?

12. What is dirty checking in Hibernate/JPA?

13. What is flush() vs commit() in JPA?

14. What is fetch type and its defaults for relationships? (EAGER vs LAZY)

15. What is cascading and cascade types in JPA?

16. What is the N+1 select problem and how can it be avoided?

17. What is the difference between JPQL and SQL?

18. What is a native query and how to write one in Spring Data JPA?

19. When would you use @Query annotation over derived queries?

20. What is the difference between save() and saveAndFlush()?

21. What is the purpose of @Transactional in Spring Data JPA?

22. Explain Optimistic vs Pessimistic Locking.

23. What are JPA lock modes?

24. What is Auditing in Spring Data JPA and how do you enable it?

25. What is the Criteria API and when do you use it?

Entity & Relationship Mapping Questions

1. How do you define a composite primary key in JPA?

2. What is the difference between @Entity and @Table?

3. What are the various JPA relationship mappings (@OneToOne, @OneToMany, @ManyToOne, @ManyToMany)?

4. What is mappedBy attribute used for?

5. How do you map bidirectional relationships?

6. Explain JoinTable vs JoinColumn.

7. What is @EmbeddedId and @IdClass?

8. What is orphanRemoval?

9. How to handle inheritance mappings in JPA? (SINGLE_TABLE, JOINED, TABLE_PER_CLASS).

10. What is @ElementCollection?

Advanced & Practical Usage Questions

1. How to implement Pagination and Sorting in Spring Data JPA?

2. What is Projections and DTO projections in Spring Data JPA?

3. Explain Query by Example (QBE) in Spring Data JPA.

4. How do you write Custom Repository Implementation?

5. What is Specification API?

6. How does Spring Data JPA handle Transactions internally with save/read methods?

7. What are some performance optimization tips in Spring Data JPA?

8. How to handle batch inserts/updates with Spring Data JPA?

9. How do you handle large datasets efficiently?

10. What is Entity graph in Spring Data JPA?

11. What is @Modifying annotation and when to use it?

12. What are custom converters and how to use them?

13. How do you handle exception translation in Spring Data JPA?

14. How do you test Spring Data JPA repositories using @DataJpaTest?

15. Explain second level cache and how to configure it with Spring Data JPA.

InterviewExpert.org

Writing about interviews, stacks, and getting hired.

Leave a comment