What is the Difference Between JPA and Hibernate?


In this short article, we will discuss what is the difference between the Java Persistence API and Hibernate ORM Framework?.

Let's first familiar with the definition of JPA and Hibernate so this will make easy to discuss the difference JPA and Hibernate.

What is the Java Persistence API? 

The Java Persistence API which provides a specification for persisting, reading, managing data from your Java object to relational tables in the database.

Read more about JPA at JPA Tutorial - Java Persistence API (you will learn everything about JPA here)

What is Hibernate Framework?

Hibernate is an Object/Relational Mapping solution for Java environments. Object-relational mapping or ORM is the programming technique to map application domain model objects to the relational database tables. Hibernate is a java based ORM tool that provides a framework for mapping application domain objects to the relational database tables and vice versa.
Hibernate provides a reference implementation of Java Persistence API, that makes it a great choice as an ORM tool with benefits of loose coupling.

For example, let's look at below diagram shows mapping between Student java model and database relational student table:
Read more about Hibernate framework at Hibernate ORM Tutorial (you will learn everything about Hibernate here)

Now you are familiar with Definition of JPA and Hibernate right. Now let's discuss the difference between JPA and Hibernate.

What is the Difference Between JPA and Hibernate?

As we know that JPA is just a specification, meaning there is no implementation. You can annotate your classes as much as you would like with JPA annotations, however, without an implementation, nothing will happen. Think of JPA as the guidelines that must be followed or an interface, while Hibernate's JPA implementation is code that meets the API as defined by the JPA specification and provides the under the hood functionality.

In short, JPA is the interface while Hibernate is the implementation.

Traditionally there have been multiple Java ORM solutions:
Each of the above implementation defining its own mapping definition or client API. The JPA expert group gathered the best of all these tools and so they created the Java Persistence API standard.

The benefit of this is that you can swap out Hibernate's implementation of JPA for another implementation of the JPA specification.

You should also read more answers to this question on StackOverflow at What's the difference between JPA and Hibernate? [closed]
You may also like to read - What Is the Difference Between Hibernate and Spring Data JPA?

Comments