Spring Data JPA Basics
Fast recall
Quick revision
Core answer
Whether you understand the difference between the JPA specification, Hibernate as its implementation, and Spring Data JPA as the convenience layer on top.
Confusing JPA (the spec) with Hibernate (the implementation), or not understanding the EntityManager and persistence context lifecycle.
Explain entity states (transient, persistent, detached, removed), the N+1 query problem, and how Spring Data JPA derives SQL from method names.
Interview-ready guide
Interview answer
JPA is the Java Persistence API, a specification for object-relational mapping.
It maps Java classes annotated with @Entity to database tables, and it lets you interact with the database through an EntityManager instead of writing raw SQL and JDBC code. The reason it exists is the impedance mismatch between objects and tables: objects have inheritance and associations, while tables have rows and foreign keys, and bridging that gap manually in every application is repetitive and error-prone.
Hibernate is the most popular implementation of the JPA spec, and Spring Data JPA builds on top by generating repository implementations from interface method names, so you can write findByPriceLessThan and Spring derives the SQL at runtime. The key concept to understand is the persistence context -- it is a first-level cache that tracks entity state changes and synchronizes them with the database on commit.
The biggest pitfall I watch for is the N+1 problem, where a lazy relationship triggers a separate query per entity, which I solve with join-fetch or entity graphs.
Spring Data JPA Basics
Direct Answer
JPA (Java Persistence API) is a specification (jakarta.persistence) that maps Java objects to relational database tables, letting developers save and query entities using object-oriented APIs instead of hand-written SQL and JDBC boilerplate. It exists because relational databases and object-oriented languages have an impedance mismatch -- objects have identity, inheritance, and associations, while tables have rows, foreign keys, and joins -- and bridging that gap manually in every application is repetitive and error-prone. Hibernate is the most popular JPA implementation, and Spring Data JPA builds on top of JPA to eliminate even the persistence-layer boilerplate by generating repository implementations from interface method names.
Common Mistakes & Pitfalls
Confusing JPA (the spec) with Hibernate (the implementation), or not understanding the EntityManager and persistence context lifecycle.
Check your understanding
Answer these without looking back at the article.
- What is the difference between JPA, Hibernate, and Spring Data JPA?
- What are the four entity states in the JPA persistence context?
- What is the N+1 query problem and how do you solve it in JPA?
- How does Spring Data JPA derive SQL from repository method names?
- What is the difference between LAZY and EAGER fetch types in JPA?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.