Scrivio Interview library
ConceptFoundations5 min read · updated 12 November 2026

What is the difference between JPA (Jakarta Persistence) and Hibernate?

Jakarta Persistence (JPA) is the specification: a set of annotations, the EntityManager API, the JPQL query language and the Criteria API that define how Java objects map to relational tables. Hibernate ORM is one implementation of that specification, EclipseLink is another, and Hibernate adds features beyond the spec such as its own annotations and filters. Spring Data JPA sits on top of the JPA API and generates repositories, using Hibernate as the provider by default in Spring Boot.

Why this question is asked

Developers often say JPA and Hibernate as if they were the same thing, and in a Spring Boot application they mostly behave as one. But the difference matters when we read an error message, choose an annotation from the wrong package, or need a feature the specification does not have. Interviewers ask this to check that we know which layer does what. In this answer, we will recap what a specification is, look at what Jakarta Persistence defines, see what Hibernate implements and adds, and place Spring Data JPA on top of the stack with an example.

1A Quick Recap: Specification Versus Implementation

A specification is a document plus a set of Java interfaces and annotations that describe behaviour, without the code that performs it. An implementation is a library that provides that behaviour. The arrangement lets us write code against the standard API while choosing, in principle, which library runs it. JDBC is a familiar example: java.sql.Connection is the API, and the PostgreSQL driver implements it.

Jakarta Persistence, formerly the Java Persistence API, works the same way. Its interfaces live in jakarta.persistence (javax.persistence before Jakarta EE 9). Version 3.1 came with Jakarta EE 10 and version 3.2 with Jakarta EE 11.

2What Jakarta Persistence Defines

The specification covers four main areas. Mapping annotations such as @Entity, @Id, @GeneratedValue, @Column, @OneToMany and @ManyToOne describe how a class maps to a table. The EntityManager is the API for working with entities: persist(), find(), merge(), remove() and creating queries. It manages a persistence context, a first-level cache that tracks loaded entities and writes their changes back at flush time. JPQL is an object-oriented query language that queries entities and their fields instead of tables and columns. And the Criteria API builds the same queries in type-safe Java code.

Java
import jakarta.persistence.*;
@Entity
public class Customer {
@Id @GeneratedValue Long id;
String name;
String email;
}
// Pure JPA code: no Hibernate import anywhere
Customer c = em.find(Customer.class, 1L); // SELECT ... WHERE id = 1
c.name = "Asha R"; // tracked by the persistence context
List<Customer> list = em.createQuery(
"select c from Customer c where c.email like :d", Customer.class)
.setParameter("d", "%@example.com")
.getResultList(); // 3 customers
// On commit: UPDATE customer SET name = 'Asha R' WHERE id = 1

Notice that everything above uses only jakarta.persistence types. In theory it would run unchanged on any JPA provider.

3What Hibernate Implements and Adds

Hibernate ORM implements all of this: it reads the annotations, generates SQL for the database dialect, manages the persistence context and translates JPQL into SQL. Hibernate 6 implements Jakarta Persistence 3.0 and 3.1, and Hibernate 7 implements 3.2. Its native API, the Session, extends EntityManager, so we can unwrap one from the other.

Hibernate also has features the specification does not. @BatchSize loads lazy collections for many parents in one query, @NaturalId maps a business key such as an ISBN with its own cache, @Filter applies a reusable condition such as tenant_id = :tenant to every query on an entity, @Formula maps a computed SQL expression to a field, and HQL is a superset of JPQL. It also offers StatelessSession for bulk work and custom type mappings. These live in org.hibernate packages, which is the quick way to recognise provider-specific code.

Java
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.NaturalId;
@Entity
public class Book {
@Id @GeneratedValue Long id;
@NaturalId String isbn; // Hibernate-only
@OneToMany(mappedBy = "book")
@BatchSize(size = 50) // Hibernate-only
List<Review> reviews;
}
Session session = em.unwrap(Session.class); // from JPA to Hibernate's native API
Book b = session.bySimpleNaturalId(Book.class).load("978-0134685991");

EclipseLink, the other major implementation and the reference implementation of the specification, has its own extensions in org.eclipse.persistence packages. Code that uses them only works on that provider.

4Where Spring Data JPA Fits

Spring Data JPA is neither the specification nor an implementation. It is a library that builds repositories on top of the JPA API. We declare an interface extending JpaRepository, and Spring generates the implementation at runtime, deriving queries from method names or from @Query annotations, all executed through the EntityManager. Spring Boot's spring-boot-starter-data-jpa brings in Spring Data JPA and Hibernate as the default provider.

Java
public interface CustomerRepository extends JpaRepository<Customer, Long> {
List<Customer> findByEmailEndingWith(String domain); // derived JPQL query
}
customerRepository.findById(1L); // calls em.find(Customer.class, 1L)
customerRepository.findByEmailEndingWith("@example.com"); // 3 customers
Step throughThe persistence stack in a Spring Boot application
  1. Your codeServices call repositories
  2. Spring Data JPAGenerated repositories, derived queries
  3. Jakarta Persistence APIEntityManager, JPQL, annotations
  4. Hibernate ORMImplementation: SQL generation, caching
  5. JDBC and driverConnections from HikariCP
  6. DatabasePostgreSQL, MySQL, Oracle

6 layers, from the top down. Step through them one at a time.

Each layer depends only on the one below it.

5Follow-up questions

Can we switch from Hibernate to EclipseLink?

In principle, yes, for code that uses only the specification: change the dependency and the provider configuration. In practice, applications often use Hibernate-specific annotations or behaviour such as lazy loading details and SQL generation differences, so a switch needs testing. Few teams ever do it.

Why do some error messages mention Hibernate when we only use JPA?

Because Hibernate is the code actually running. An exception such as LazyInitializationException or a Hibernate SQL warning comes from the implementation behind the EntityManager. JPA defines some exceptions too, such as EntityNotFoundException, but many runtime errors come from the provider.

Is JPQL the same as HQL?

JPQL is the query language defined by the specification. HQL, Hibernate Query Language, is Hibernate's own language and a superset of JPQL, so every valid JPQL query is valid HQL, but HQL adds features. A query using those extras is tied to Hibernate.

6Conclusion

In this answer, we saw that Jakarta Persistence is the specification, defining mapping annotations, the EntityManager, JPQL and the Criteria API, and that Hibernate ORM and EclipseLink are implementations of it. Hibernate adds its own features in org.hibernate packages, such as @BatchSize, @NaturalId and filters, and Spring Data JPA builds repositories on top of the JPA API, with Hibernate as the default provider in Spring Boot.

What to say in the interviewAbout 80 seconds aloud

Open with

JPA, now Jakarta Persistence, is a specification. It defines the mapping annotations like @Entity, @Id and @OneToMany, the EntityManager API with persist, find, merge and the persistence context, the JPQL query language and the Criteria API, all in the jakarta.persistence package.

Then, if they want more

It is only interfaces and rules; it does not generate any SQL itself. Hibernate ORM is an implementation of that specification, and EclipseLink is another one. Hibernate reads the annotations, generates the SQL for our database, manages the first-level cache and translates JPQL.

It also goes beyond the spec with features in org.hibernate packages, such as @BatchSize to avoid N+1 queries, @NaturalId, filters for things like multi-tenancy, @Formula, HQL as a superset of JPQL, and its native Session API, which we can unwrap from the EntityManager.

Spring Data JPA is a third, separate layer: it builds repositories on top of the JPA API, so we declare an interface extending JpaRepository and Spring generates queries from method names.

In a Spring Boot app the starter uses Hibernate as the provider by default, so in practice our code talks to Spring Data, which talks to JPA, which Hibernate implements.

About this answer

Last updated
12 November 2026
Versions it names
Hibernate 6, Hibernate 7, Jakarta EE 10, Jakarta EE 11
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Jakarta EE specifications
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is the difference between JPA (Jakarta Persistence) and Hibernate?": https://scrivio-interview-library.netlify.app/java/jakarta-ee-platform/6bf1bcea09/