• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference JPA/hibernate?

 
numan ali
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can someone explain how JPA and Hibernate are different, or related? I looked this up online and "kind of" understand it, but not really. I have VERY minimal hibernate experience, virtually none, so please keep that in mind, and provide a simple, easy to grasp answer

Gracias
 
numan ali
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and for eclipse, I got hibernate downloaded and set, do I need to download anything to use, or make use of JPA?

thanks
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPA, or Java Persistence API, is a programming interface. As such, it only defines which actions (interfaces and their methods mostly) are available to a program that wants to make use of the JPA. Hibernate is a specific implementation (one of several available) of this API.

It is kind of similar to JDBC and JDBC drivers. JDBC defines actions you can use when accessing the database from Java, but to connect to a specific database, you need an JDBC driver. JDBC is the interface, JDBC driver is an implementation.
 
numan ali
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin, thanks, but I still dont get it, im not very familiar with the JDBC either.

If I go online and study hibernate tutorials, will I be learning JPA in the process? or if I go online and study JPA tutorials, will I learn hibernate in the process?

With that said, do you have a link to good tutorials on hibernate/jpa, either youtube or a site? If you can please post one or more, I would appreciate it, Im really in a crunch to learn ASAP

thanks
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try to come up with a different example: Consider java.util.List (an interface) and java.util.LinkedList (an implementation of this interface). List - the interface - just defines all actions you can do with any list implementations. You can learn how to use a list from a documentation or a tutorial. Then you'll know how to use lists in your code. But to actually use a list in your code, you need to use one of available implementations. LinkedList is just one of several (another is an ArrayList, for example). And these implementations can have some specifics: LinkedList implements more methods than just those prescribed by the List interface (such as push() and pop()), but you cannot use them with Lists in general. Also, you need to learn how to create or initialize lists - it's an easy deal, of course, you just use the proper constructor, but constructors are not part of the interface (they cannot be), so you don't learn about them just by studying the List interface.

In this analogy, the JPA is an interface and Hibernate is one of the implementations (OpenJPA is another, for example). So if you'll learn Hibernate, you'll learn something more than just JPA - namely, you'll also learn how to configure and initialize Hibernate in your project, which is essential, but not covered by JPA. If you study JPA tutorials that do not describe any specific implementation, you'll have to learn the missing bits when actually trying to use some implementation in your project.

I personally would probably just start with Hibernate, in the hope that by the time I get well versed in it, the differences between JPA and Hibernate will become much easier to grasp.

I don't have experiences with Hibernate tutorials myself, but I'd probably start with the one hosted by Hibernate itself: http://docs.jboss.org/hibernate/orm/3.5/reference/en/html/tutorial.html. You might also try to search in our book reviews forum or in the Bunkhouse, if you are interested in books on the topics as well.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally would probably just start with Hibernate, in the hope that by the time I get well versed in it, the differences between JPA and Hibernate will become much easier to grasp.

I would start the other way around (learn JPA), mostly because using the standard API generally feels like a better approach to me. However, Hibernate (meaning its native API, not as a JPA implementation) is so widely used that it could with some justification be viewed as a standard in its own right. While the Hibernate API does some things that JPA doesn't, I would estimate that at least 90% (maybe 95%) of apps do not need those extra features, so using JPA would be just fine. And both use similar concepts, so learning one will help with learning the other at an abstract level. (Looking at job descriptions you will see Hibernate being mentioned a lot more than JPA, simply because its use is so widespread, and it has been around for longer.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic