16

Hibernate website says there is a native Hibernate API as well as an implementation of JPA. What is the difference between the Native API and JPA implementation? Advantages, disadvantages?

I am working on a Spring MVC application, using Tomcat as the container, and MySQL for persistence. I've used Doctrine and Entity for PHP and .NET respectively in the past, using the code first approach. I would like to have something similar with Java. I'm newer to Spring and never used Hibernate. My team would like to use an ORM and Hibernate seems to be the most popular. We're not sure how Hibernate is going to workout or whether we should use native or JPA api. The application will be data driven, data entry, reporting, etc.

I've read that using JPA makes its easier to switch to another JPA implementation, although I don't know if that will be needed or not.

0

1 Answer 1

31

JPA is a standard for accessing relational databases through an object oriented API. Hibernate is an implementation of this API. When you want to use JPA you need some vendor to implement it, Hibernate is a good choice but there are others like EclipseLink.

Hibernate exists longer than JPA. The native, older API (which was a model for JPA) still exists, and sometimes it offers more possibilities than are exposed through JPA (e.g. orphan removal). If you need those you need to use the native API. Using JPA has other merits, most important (in my opinion) more developers that know it. And you still can use some Hibernate specifics through configuration.

In general IMO it pays to use the standard API, here JPA, and do an experienced decision on the implementation to use.

Most tutorials that use Hibernate natively are quite old - as is Hibernate 3, a pre-JPA release. While there are good reasons to use it, they (IMO) typically don't apply to the general audience. So if you are just beginning to learn in this field I would suggest to start with JPA.

As for recommendations on offsite resources: For good reasons they are not on topic here. But the current official Hibernate documentation would be a good start, as would be to look for toturial for at least Hibernate 4.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.