Difference Hibernate 3.5 / JPA 2.0

jplandrain picture jplandrain · Jun 29, 2010 · Viewed 7.2k times · Source

So far, I always prefered to use Hibernate directly rather than JPA 1.0, because JPA was lacking some of the important features I needed and Hibernate provided: Criteria API, second level cache, unidirectional OneToMany and a few others.

Now, with the advent of JPA 2.0 and all the new features that come with it and that were initially missing in JPA 1.0 (http://en.wikibooks.org/wiki/Java_Persistence/What_is_new_in_JPA_2.0%3F), I wonder if there is still a need to use Hibernate directly.

What's your opinion? What's left in Hibernate 3.5 that I can't do with JPA 2.0 ?

Answer

Pascal Thivent picture Pascal Thivent · Jun 29, 2010

Now, with the advent of JPA 2.0 and all the new features that come with it and that were initially missing in JPA 1.0 (http://en.wikibooks.org/wiki/Java_Persistence/What_is_new_in_JPA_2.0%3F), I wonder if there is still a need to use Hibernate directly.

Even for JPA 1.0, I would recommend a different approach: "JPA where you can, Hibernate where you must".

What's your opinion? What's left in Hibernate 3.5 that I can't do with JPA 2.0 ?

JPA 2.0 is very rich and I consider it as a huge improvement and many things that were requiring to use proprietary extensions are now standardized (see this previous answer).

But you might still need some Hibernate specific extensions in some situations: a custom UserType, a non standard generator, a query by example, @Formula, @Index, etc. Have a look at the Section 2.4, “Hibernate Annotation Extensions” for more "examples".

But let me insist, I recommend to use JPA where you can, Hibernate where you must (the later part getting thiner with JPA 2.0).