74

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

Community
  • 1
  • 1
M Sach
  • 33,416
  • 76
  • 221
  • 314
  • You are absolutely right. ORM is simply a name for the concept or mapping OO -> RMDBS. JPA is the Java Persistence API, specified as part of the JavaEE spec. Hibernate is one of the implementations or that API. There are many versions of JPA and different versions of Hibernate implement different versions of the JPA API. – Boris the Spider Dec 13 '14 at 18:30
  • 3
    I am not sure why it received negative vote that too with in 5 seconds of posting. Would appreciate if downvoter can give me feedback so that i can improve next time – M Sach Dec 13 '14 at 18:31
  • @BoristheSpider Thanx. Am i correct about JPA too ? – M Sach Dec 13 '14 at 18:34
  • 1
    Mostly there. JPA isn't a "high level" API, it's just a specification of an ORM framework. It's very similar to the Java Servlet API or the Java Transaction API etc - all part of JavaEE. iBATIS isn't a JPA implementation. – Boris the Spider Dec 13 '14 at 18:41
  • So, what is the question here? – Vladimir Vaschenko Oct 13 '15 at 05:01
  • 6
    "I am not sure if i am right about JPA vs ORM" Implies **Am I right about JPA vs ORM?** So I think there is a question, Some people just like to downvote I think. – Arthur Jun 08 '16 at 08:27

2 Answers2

55
  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.

Kevin Hooke
  • 2,583
  • 2
  • 19
  • 33
  • 2
    @HalfBloodPrince, As Kevin said above, ORM is the approach of mapping objects to relational database tables. Any framework which provide object-database table mapping mechanism are called ORM frameworks. Hibernate is ORM framework already there in market before JPA specification came into existence. Earlier there was their own implementation of Hibernate (A ORM framework) , after then Hibernate created implementation of JPA. Today, there are two flavor of Hibernate 1. Own implementation 2. JPA implementation – Rakesh Bhalani Jan 09 '19 at 11:50
  • 1
    @RakeshBhalani I think it's clearer to say a subset of Hibernate's features provide an implementation of the JPA spec, and in additional Hibernate provides additional features that are above and beyond the features required in the JPA spec. In other words, the JPA part of Hibernate is a subset of the complete set of features Hibernate provides – Kevin Hooke Jan 09 '19 at 21:30
3

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.