JPA Specification vs Hibernate Implementation
Fast recall
Quick revision
Core answer
jakarta.persistence package. Hibernate is a concrete implementation of that specification — it's the actual code that does the object-relational mapping. Spring Data JPA uses Hibernate as its default JPA provider.Understanding the difference between a specification (contract) and its implementation
Using JPA and Hibernate interchangeably without realizing JPA is just an interface and Hibernate is the implementation
Use the JDBC analogy: JPA is like the JDBC API itself, Hibernate is like the MySQL Connector/J driver that implements it
Interview-ready guide
Interview answer
JPA is a specification — it's just interfaces and annotations that define how object-relational mapping should work in Java.
persistence package. Things like the Entity interface, the EntityManager interface, and annotations like @Entity and @OneToMany are all defined by JPA. But there's no implementation code.
Hibernate is the actual implementation that makes JPA work. It's the library that contains the code to generate SQL from your entities, manage the persistence context, handle caching, and execute queries. When you annotate a class with @Entity, you're using JPA's annotation, but Hibernate is what reads that annotation and generates the database schema.
Think of it like JDBC. JDBC is a specification with interfaces like Connection and ResultSet. The MySQL driver or PostgreSQL driver is the implementation that actually talks to the database.
Same relationship here — JPA is the spec, Hibernate is the provider. In Spring Boot, when you add the spring-boot-starter-data-jpa dependency, it automatically includes Hibernate as the default JPA provider. There are other providers like EclipseLink, but Hibernate is by far the most common.
One thing to watch for — Hibernate offers features beyond JPA like the @Formula annotation or batch fetching strategies. Those won't work if you switch providers because they're Hibernate-specific extensions.
JPA Specification vs Hibernate Implementation
Direct Answer
JPA is a specification defining how ORM should work in Java through interfaces and annotations in the jakarta.persistence package. Hibernate is a concrete implementation of that specification — it's the actual code that does the object-relational mapping. Spring Data JPA uses Hibernate as its default JPA provider.
Code Example
import jakarta.persistence.*;
import org.springframework.data.jpa.repository.JpaRepository;
// JPA annotations define the structure
@Entity // JPA specification annotation
@Table(name = "orders")
public class Order {
@Id // JPA defines this as primary key
@GeneratedValue(strategy = GenerationType.IDENTITY) // JPA strategy
private Long id;
private String customerName;
private Double totalAmount;
@ManyToOne(fetch = FetchType.LAZY) // JPA relationship
@JoinColumn(name = "customer_id") // JPA join definition
private Customer customer;
}
// Spring Data JPA repository - uses Hibernate underneath
interface OrderRepository extends JpaRepository<Order, Long> {
// Method name converted to JPQL by Spring Data, executed by Hibernate
List<Order> findByCustomerName(String name);
}
Common Mistakes & Pitfalls
- Using Hibernate and JPA as synonyms: Learners say they're using JPA when they mean Hibernate specifically, or ask about JPA features that are actually Hibernate extensions. This confusion makes it hard to distinguish standard behavior from vendor-specific features.
- Not knowing where to look for documentation: When encountering an issue, Learners search Hibernate docs for standard JPA behavior or JPA specs for Hibernate-specific features, wasting time in the wrong resource.
- Thinking Spring Data JPA is JPA: Spring Data JPA is another layer on top — JPA is the ORM spec, Hibernate implements it, Spring Data JPA adds repository conveniences. All three are distinct layers.
Check your understanding
Answer these without looking back at the article.
- What other JPA implementations exist besides Hibernate?
- What is the difference between EntityManager and Session in Hibernate?
- What does Spring Data JPA add on top of Hibernate?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.