Spring Data JPA — Relationship to Hibernate and JDBC
Fast recall
Quick revision
Core answer
findByName — it auto-generates queries from method names. The full stack top-to-bottom is Spring Data JPA → Hibernate (JPA provider) → JDBC driver → database.Understanding the full Spring Data JPA technology stack and how layers compose
Thinking Spring Data JPA is an ORM itself, when it's actually a convenience layer over Hibernate/JPA
Clearly draw the layering: Spring Data JPA adds repositories, Hibernate does ORM, JDBC handles database communication
Interview-ready guide
Interview answer
Spring Data JPA is a repository abstraction layer that sits on top of JPA to make data access even easier.
It's not an ORM itself — it uses Hibernate or another JPA provider underneath. The big feature is that you define an interface extending JpaRepository and Spring generates the implementation for you at runtime. You never write the actual class.
The cool part is query derivation. lastName equals the parameter. You can make it more complex like findByAgeGreaterThanAndCity and it still works.
For queries that don't fit the naming convention, you can use the @Query annotation with custom JPQL or even native SQL. The full technology stack is important to understand. At the top you have Spring Data JPA providing the repository interface.
That talks to JPA, which is the specification. JPA is implemented by Hibernate, which does the actual object-relational mapping. Hibernate then uses a JDBC driver like the PostgreSQL driver to communicate with the database.
So it's four layers stacked on each other. One thing Learners get wrong is thinking Spring Data JPA replaces Hibernate. It doesn't.
It's built on top of it. If you see a LazyInitializationException, that's coming from Hibernate's layer, not Spring Data JPA. Spring Data JPA just makes the repository pattern easier to implement.
It's a huge productivity boost for typical CRUD applications.
Spring Data JPA — Relationship to Hibernate and JDBC
Direct Answer
Spring Data JPA is a repository layer on top of JPA (usually Hibernate) that provides interfaces with method-naming conventions like findByName — it auto-generates queries from method names. The full stack top-to-bottom is Spring Data JPA → Hibernate (JPA provider) → JDBC driver → database.
Code Example
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
// Spring Data JPA interface - no implementation needed
public interface CustomerRepository extends JpaRepository<Customer, Long> {
// Query derived from method name
List<Customer> findByLastName(String lastName);
// More complex derived query
List<Customer> findByAgeGreaterThanAndCityOrderByLastNameAsc(
int age, String city);
// Custom JPQL when naming gets awkward
@Query("SELECT c FROM Customer c WHERE c.email LIKE %:domain")
List<Customer> findByEmailDomain(String domain);
// Native SQL when JPQL isn't enough
@Query(value = "SELECT * FROM customers WHERE created_at > NOW() - INTERVAL '30 days'",
nativeQuery = true)
List<Customer> findRecentCustomers();
}
// Usage in service - Spring generates implementation
@Service
class CustomerService {
private final CustomerRepository repository;
List<Customer> getYoungCustomersInCity(String city) {
return repository.findByAgeGreaterThanAndCityOrderByLastNameAsc(18, city);
}
}
Common Mistakes & Pitfalls
- Thinking Spring Data JPA is an ORM: Learners believe Spring Data JPA is a separate ORM competing with Hibernate, when it's actually just a convenience layer on top of JPA/Hibernate. This confusion leads to misunderstanding error messages and configuration.
- Confusing Spring Data JPA with Spring Data JDBC: These are different modules — Spring Data JPA uses Hibernate and full JPA semantics (lazy loading, caching, dirty checking), while Spring Data JDBC is a simpler mapper without those features. They're not interchangeable.
- Over-relying on derived queries: Beginners create methods named findByFirstNameAndLastNameAndCityAndStatusAndCreatedDateBetween which become unreadable — switching to @Query with JPQL would be cleaner. They don't know when to stop using the naming convention.
Check your understanding
Answer these without looking back at the article.
- How does Spring Data JPA generate SQL from method names?
- What is JpaRepository and what methods does it provide?
- How do you write custom queries in Spring Data JPA?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.