Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA vs ORM vs Hibernate?

I have read about them through various resources. Importants ones are :-

  1. Wikipedia article about each of them
  2. What's the difference between JPA and Hibernate?

Here is my understanding about whats the difference b/w them. I am not sure if i am right about JPA vs ORM

  1. ORM: Object Relational Mapping is concept/process of converting the data from Object oriented language to relational DB and vice versa For example in java its done with the help of reflection and jdbc.

  2. Hibernate: Its the implementation of above concept.

  3. JPA: Its the one step above ORM. Its high level API and specification so that different ORM tools can implement so that it provides the flexibility to developer to change the implementation from one ORM to another (for example if application uses the JPA api and implementaion is hibernate. In future it can switch to IBatis if required. But on the other if application directly lock the implementation with Hibernate without JPA platform, switiching is going to be herculean task)

There can be ORM implementation with/without JPA specification.For example as per this link under hibernate section only Hibernate versions 3.2 and later provide an implementation for the Java Persistence API

like image 503
M Sach Avatar asked Dec 13 '14 18:12

M Sach


People also ask

What is the difference between JPA Hibernate and ORM?

Java Persistence API (JPA) defines the management of relational data in the Java applications. Hibernate is an Object-Relational Mapping (ORM) tool which is used to save the state of Java object into the database. It is just a specification. Various ORM tools implement it for data persistence.

Is JPA and ORM same?

The Java Persistence API (JPA) is a specification that defines how to persist data in Java applications. The primary focus of JPA is the ORM layer. Hibernate is one of the most popular Java ORM frameworks in use today.

What is difference between ORM and Hibernate?

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.


2 Answers

  1. ORM is the approach of taking object-oriented data and mapping to a relational data store (e.g. tables in a RDBMS)

  2. JPA is the Java EE standard specification for ORM in Java EE.

  3. The reference implementation for JPA is EclipseLink. If you don't explictly configure a provider, EclipseLink is used under the covers.

  4. Hibernate is another implementation of the JPA specification, in that you can use the standard JPA APIs and configure your application to use Hibernate as the provider of the spec under the covers.

  5. Hibernate also provides a superset of the ORM features beyond what is specified in the JPA spec. Meaning, that while it provides an implementation of the JPA API, it also provides more features beyond what JPA specifies.

like image 52
Kevin Hooke Avatar answered Oct 16 '22 14:10

Kevin Hooke


The only mistake you seemed to make in your understanding is

Its the one step above ORM

One quick note, The libraries starting with javax.persistence are associated with JPA. You should prefer these over Hibernate Libraries whenever possible. Because these are Portable. However, you will get some extra features in Hibernate, and in those precise cases, please feel free to use Hibernate.

like image 3
Miguel Ángel Avatar answered Oct 16 '22 13:10

Miguel Ángel