This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why use JPA over Hibernate?  RSS feed

 
Ranch Hand
Posts: 591
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why should I use Hibernate using it's java persistence layer i.e JPA. I can directly use Hibernate without the JPA. One reason I definitely know, I can switch between multiple JPA implementation frameworks without any pain. But if I am not wrong, anyone would change the ORM framework very rarely, unless they have a strong reason to do so.
Are there any other benefits of using JPA? But pros are backed with some cons as well. Are there any other cons of using JPA over Hibernate. Can someone please give me good exposure on this?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPA is Specification, Hibernate is reference Implementation Hibernate is Implemented as per JPA Standards hope it gives some thought to it
 
Author and ninkuma
Marshal
Posts: 66681
167
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sanjeev Biradar wrote:JPA is Specification, Hibernate is reference Implementation Hibernate is Implemented as per JPA Standards hope it gives some thought to it


But that doesn't really address the question: with Hibernate, you can choose to use a proprietary Hibernate API, or JPA. I'd recommend going with JPA, not only because the code then adheres to a standard interface that can be independent of the specific implementation (which is almost always the right approach), but also because the JPA community will be wider. When you are looking for answers, help for JPA will be more widely available.
 
Puspender Tanwar
Ranch Hand
Posts: 591
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:But that doesn't really address the question: with Hibernate, you can choose to use a proprietary Hibernate API, or JPA. I'd recommend going with JPA, not only because the code then adheres to a standard interface that can be independent of the specific implementation (which is almost always the right approach), but also because the JPA community will be wider. When you are looking for answers, help for JPA will be more widely available.

Along with the plus point of community support, if someday I find JPA can't do any task but Hibernate can do, I can directly use Hibernate without JPA standards, right?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66681
167
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dunno. In almost 10 years of using JPA/Hibernate, I've never come across such a situation.
 
Puspender Tanwar
Ranch Hand
Posts: 591
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Dunno. In almost 10 years of using JPA/Hibernate, I've never come across such a situation.

Hello Bear, since you are the right person to ask, what would be the best way to learn JPA/Hibernate. Ofcourse I know the best way is to get hands-on, but I should know the basics first. As of now I have gone through the basics of JPA-Hibernate from an online video course and implemented whatever is adviced in that. But I really want to know, what book should I follow, since you know I am a beginner to persistence world. I already bought high-performance java persistence by Vlad Mihalcea, but that's not a beginners book actually(I bought because it was on black Friday sale).
It would be a great help if you can consult me the best resources.
 
Saloon Keeper
Posts: 4477
112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sanjeev Biradar wrote:Hibernate is reference Implementation


No, EclipseLink is. Hibernate is probably more widely used, though.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66681
167
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Puspender Tanwar wrote:what would be the best way to learn JPA/Hibernate. Ofcourse I know the best way is to get hands-on


Yup. Write lots of code. But I got my start with Cameron McKenzie's book Hibernate Made Easy. I don't know if it still in print. The formatting is a bit wonky, but I found it a good place to start.
 
Puspender Tanwar
Ranch Hand
Posts: 591
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Puspender Tanwar wrote:what would be the best way to learn JPA/Hibernate. Ofcourse I know the best way is to get hands-on


Yup. Write lots of code. But I got my start with Cameron McKenzie's book Hibernate Made Easy. I don't know if it still in print. The formatting is a bit wonky, but I found it a good place to start.

It's not under print now. Amazon is selling a 2008 version copy which covers Hibernate 3.2.
So definitely it's not good for today actually.
 
Bartender
Posts: 19454
88
Android Eclipse IDE Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a real good reason to prefer Hibernate JPA over legacy Hibernate.

The Hibernate team was one of the most active participants in the creation of JPA.

Effectively, then, it was how they would have designed Hibernate with the resources and knowledge that they gained from their previous architecture.

The fact that you can (and I have done so) switch between JPA providers (from Apache OpenJPA to Hibernate JPA) with just 3 changes to a project's Maven POM and the addition of 2 simple config files is nice, too.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66681
167
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Puspender Tanwar wrote:So definitely it's not good for today actually.


Hibernate may have changed, but the core of JPA covered still exist. Hmm, perhaps yet another argument for JPA over the proprietary API.

In fact, I kinda look at it as a more general instance of "code to the interface, not the implementation".

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66681
167
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also read Java Persistence with Hibernate and found it to be very complete, but not as quite as approachable. There is a second edition out; not sure how up-to-date it is.
 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!