Hibernate and JPA are the same thing?

Asked

Viewed 1,706 times

3

It is a question of who just took this subject to study but confuses me a lot. I read some articles about ORM and did not understand very well what is one and what is the other, are the same thing? Can you use one without the other? Where each one is distinguished?

3 answers

8


Hibernate is a technology, it was the first ORM technics for Java. With the popularization of the same the Oracle (company maintainer of Java at the time) ended up inviting the creators of Hibernate to build JPA which is a specification indicating how to implement any ORM framework to standardize the way the final developer works with them.

In addition to Hibernate another JPA framework is Eclipselink.


The relationship between them would be like this:

  • JPA is a specification that defines a common interface for ORM frameworks;
  • Hibernate is a framework that implements JPA;
  • Eclipselink is another framework that also implements JPA and is thus a competitor of Hibernate.

4

JPA is just a specification, there is no implementation. Think of JPA as a set of guidelines that should be followed in the implementation.

Hibernate is one of the implementations that follows these guidelines. One of the benefits of using JPA is the possibility to change implementation, as they all use the same interface. There are other implementations besides Hibernate, such as Eclipselink and Toplink.

Reference

2

They are not. This is a very common doubt, which I even had in my first years of development with Hibernate.

JPA means Java Persistence API. Is a specification of a "Java API for persistence management and object/relational mapping in Java EE and Java SE environments".

Basically, JPA brings together a set of rules that allows anyone to implement this API, allowing them to use this implementation in any project that uses JPA interfaces, thus ensuring a certain compatibility between different implementations.

This is where the Hibernate. Hibernate is an implementation of the JPA specification, certainly the most common and used. In addition to Hibernate, we also have other JPA implementations, such as Openjpa and Eclipselink. It is common for many people to treat Hibernate and JPA as if they were one thing, so it is common for you to have a specific JPA question but to find the answer in a question that only mentions Hibernate in it. This confusion only exists because of the greater popularity of Hibernate.

In theory, if you are not using any unique features of any implementation (which is relatively common), you can exchange one implementation for another in your project transparently. For example, a common entity mapping involves annotations as @Column, @Table, @Id, etc, and they are all part of the package javax.persistence, common to any JPA implementation. Thus, a Hibernate exchange for Openjpa (for example) would transparently occur for the application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.