Khangharoth

September 6, 2007

Difference Between JPA and Hibernate

Filed under: JEE — khangharoth @ 3:44 pm

My colleague just asked me this question and i thought its quite a common question in, lot of developers mind.

Well as you might aware of now we have a much leaner and easy to use Ejb 3 specifications.

The EJB 3.0 specififcation is divided into two parts the first which deals with session and MDBs and the second which deals with persistence and entity beans.

This later part is know as JPA.And as i say latter part so this is independent of session and other concepts.This means that this can be used outside of any Server or managed Container .You can use JPA in SDK just like you write “Hello World”,no need of any Server or container.

JPA works with normal java beans so your code can be just Java beans ,some XML/annotatons about how Object’s are mapped with tables and you are good to go,very easy to write test cases as well.

And hibernate 3.0 implements the JPA specification so  TopLink and other O/R mapping framework.So your code depends upon JPA Api and its implementation is supplied by any JPA impl vendor framework.

So in effect if you use JPA , you are using a standard Java Api and not some orthogonal Api and hence you have flexibility in your system.

Say initially you have used Hibernate but now want to shift to Other framework.That means JPA supports pluggable persistence providers.

JPA specification is heavily influenced by current O/R mapping frameworks like Hibernate and Top-Link .

So if i need to put in Concise words:

a) JPA is Persistence Api which your code should use.

b) JPA Api will pass on the call to actual peristence provider (ex:Hibernate/TopLink) to do the actual work.

c) If you are looking from Performance prespective ,it will be dependent on actual peristence provider (Hibernate/TopLink) and not on JPA as its just a wrapper layer.

d) If you are looking from code dependency prespective ,JPA makes more sense as your code is dependent on standard Java Api.

e) If you have used Hibernate then you will find that certain features are missing in JPA like criteria queries etc.This does not mean that you can’t write criteria query in your application, you need to get Session object from JPA Entity manager and now you are as good as in hibernate project.

But now your code is dependent on Specific impl (Hibernate),going forward you can see more things getting added in JPA (2.0)

f) Should you use JPA: My take is you should ,API is clean and although not everthing you need is their but is a good step forward.

Hopefully this give better picture as where all these pieces fits into an Java based Enterprise Application .

About these ads

48 Comments »

  1. good explanation

    Comment by lavanya — July 6, 2008 @ 5:18 am | Reply

  2. Excellent, short and simple explanation.

    Comment by Petar — July 29, 2008 @ 10:50 pm | Reply

  3. Explanation Defines nothing specific

    Comment by y — October 24, 2008 @ 7:18 am | Reply

  4. Very good explanation.Keep this blog live.

    Comment by Jagrut — March 10, 2009 @ 5:41 pm | Reply

  5. Simple et efficace. Merci.

    Comment by anthony — April 29, 2009 @ 12:48 pm | Reply

  6. Good explanation…

    Comment by Selvaraj — June 27, 2009 @ 11:30 am | Reply

  7. Nice concise explanation. Thank you.

    Comment by kush_2207 — July 20, 2009 @ 2:25 am | Reply

  8. Nice and simple explanation. Thanks a lot.

    Comment by Sreekar — July 23, 2009 @ 6:21 pm | Reply

  9. Great.. Helped me out

    Comment by Francois — August 13, 2009 @ 12:49 pm | Reply

  10. Thx ! :) nice one

    Comment by JacQ — October 26, 2009 @ 5:15 pm | Reply

  11. Nice and simple, appreciate it!!

    Comment by Sun — November 29, 2009 @ 8:22 pm | Reply

  12. Nice one

    Comment by Amit — December 28, 2009 @ 7:37 am | Reply

  13. HI, really nice. I need this badly :)
    Thanks My dear friend khangharoth

    Comment by Palam — February 17, 2010 @ 5:27 pm | Reply

  14. Thanks! Now everything is clear!

    Comment by Alessandro — February 18, 2010 @ 11:33 am | Reply

  15. This is simple and good explanation

    Comment by mahesh — April 16, 2010 @ 6:46 am | Reply

  16. Awesome explanation, very easy and basic explanation that really helped me.
    Thanks and keep up the good work

    Comment by Ravi Verma — October 10, 2010 @ 3:19 pm | Reply

  17. Thanks for your explanation, it was quite beneficial.

    Comment by Vikas Kumar Gupta — October 21, 2010 @ 7:14 am | Reply

  18. I don’t think it is useful…

    Comment by Karthi — November 11, 2010 @ 4:20 pm | Reply

    • Does it mean that you already know the content of this article (good for you in this case), and you are looking for other information?

      Comment by muoicairangkhenh — June 9, 2011 @ 8:35 am | Reply

  19. Nice explanation

    Comment by Praveen — November 15, 2010 @ 6:29 am | Reply

  20. Nice explanation – But Business need always having higher priority over Standards. But following standards also help us to meeting business need.

    Its chicken egg – I always try to follow JPA standards but always i found some place where i need to used implement specific feature.

    Comment by kaushik vira — December 16, 2010 @ 7:19 am | Reply

  21. Thank you for good informative explanation.

    Comment by Hemang — January 16, 2011 @ 6:34 am | Reply

  22. Great, this explains that Hibernate implements JPA!
    What about the other side of the medal – what is in Hibernate that is missing in JPA?

    Comment by Rou — February 16, 2011 @ 12:16 pm | Reply

  23. HI
    This is very clear explanation for freshers who don’t know the different frameworks and what is JPA
    But one request that will u update the answer with new features.

    Comment by Krishna Ganesh — February 28, 2011 @ 9:05 am | Reply

  24. Best explanation ever ,so simple and clear.

    Comment by Seerat — March 13, 2011 @ 6:57 pm | Reply

  25. Excellent article!
    Thanks!

    Comment by theht — April 9, 2011 @ 7:39 am | Reply

  26. Very good explanation…clear and simple. I understand.

    Comment by Ezani — June 10, 2011 @ 8:55 am | Reply

    • good explanation …

      Comment by narendra — June 19, 2011 @ 9:49 am | Reply

  27. Very clear explanation to have High level idea.

    Comment by Siv — June 28, 2011 @ 4:48 pm | Reply

  28. Good Explanation as well very important information gathered.

    Comment by Piyush — July 6, 2011 @ 11:16 am | Reply

  29. Well done! However, for optimum cases, using Hibernate directly will be to your advantage. Besides, Hibernate is in itself like a standard in the industry.

    Comment by Guest — July 26, 2011 @ 4:00 pm | Reply

  30. Terrible English and spelling. However overall a good summary.

    Comment by lokke — September 20, 2011 @ 12:21 pm | Reply

  31. Thi is really helps to understand what is actually JPA.

    Comment by rajasheker — October 18, 2011 @ 10:44 pm | Reply

  32. This is simply awesome. I’ve been looking for a precise and short explanation like this. Thanks dude. I’ll be a frequent visitor here

    Comment by Ranis MK — October 26, 2011 @ 3:28 pm | Reply

  33. Very good

    Comment by Nagoor — October 31, 2011 @ 9:36 am | Reply

  34. Very clear thank you!
    I didn’t know about TopLink.

    Comment by Dating Ireland — November 13, 2011 @ 9:47 am | Reply

  35. Awesome explaination.

    Comment by Satyajeet — December 20, 2011 @ 6:02 pm | Reply

  36. perfect explanation

    Comment by Yinka — February 27, 2012 @ 3:49 pm | Reply

  37. good Explanation

    Comment by surendra mishra — March 21, 2012 @ 5:52 am | Reply

  38. [...] etc. The underlying mechanism could be changed anytime and the JPA code wouldn’t change.http://elope.wordpress.com/2007/09/06/difference-between-jpa-and-hibernate/ And hibernate 3.0 implements the JPA specification so TopLink and other O/R mapping framework.So [...]

    Pingback by The long and short of it all « Tips from a mentor to his protégé — March 21, 2012 @ 9:56 am | Reply

  39. Superb………cleared my doubts, Thx

    Comment by syed — March 28, 2012 @ 7:29 pm | Reply

  40. an information that i was looking to differentiate between these 2 (jpa and hibernate), yes it lacks some technical information on differentiation between them …but anyway it helped me out.

    Comment by jaggs — April 13, 2012 @ 5:20 am | Reply

  41. Its is nice and quick summarization of details.

    Comment by Srinivas — June 28, 2012 @ 8:42 am | Reply

  42. Really great explanation.. I like it… Before reading this blog I had understanding that Hibernate and JPA are 2 different ORM’s but after reading it’s clear that JPA standard persistence API provide by java which is kind of wrapper over hibernate which is real implementation of JPA

    Comment by Rakesh — June 29, 2012 @ 7:53 pm | Reply

  43. Really Great explanation. Short and simple. Keepi It UP :)

    Comment by Amit — August 14, 2012 @ 6:30 am | Reply

  44. This is really good explanation

    Comment by charan — March 7, 2013 @ 7:33 am | Reply

  45. Nice and clear explanation..Thanks

    Comment by Tapan — May 26, 2013 @ 7:45 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: