差异Hibernate 3.5 / JPA 2.0 [英] Difference Hibernate 3.5 / JPA 2.0

查看:131
本文介绍了差异Hibernate 3.5 / JPA 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我总是希望直接使用Hibernate而不是JPA 1.0,因为JPA缺乏我需要的一些重要功能,而Hibernate提供了:Criteria API,二级缓存,单向OneToMany和其他一些。



现在,随着JPA 2.0的出现以及随之而来的所有新功能以及最初在JPA 1.0中缺少的功能( http://en.wikibooks.org/wiki/Java_Persistence/What_is_new_in_JPA_2.0%3F ),我想知道是否有仍然需要直接使用Hibernate。



您对此有何看法? Hibernate 3.5中剩下的我无法用JPA 2.0做什么?

解决方案


现在, JPA 2.0的出现以及随之而来的所有新特性,这些特性最初在JPA 1.0中缺少( http://en.wikibooks.org/wiki/Java_Persistence/What_is_new_in_JPA_2.0%3F ),我想知道是否仍然需要直接使用Hibernate。


即使对于JPA 1.0,我也会推荐一种不同的方法:您可以在何处使用JPA,何时必须使用Hibernate。


您的意见是?在Hibernate 3.5中,我无法用JPA 2.0做什么?


JPA 2.0非常丰富,我认为它是一个巨大的改进和许多需要使用专有扩展的东西现在已经标准化(请参阅以前的答案)。

但是在某些情况下,您可能仍然需要一些Hibernate特定的扩展:自定义的 UserType ,一个非标准的生成器,以示例查询, @Formula @Index 等。看一看有关更多示例的第2.4节Hibernate注释扩展 。

但是,让我坚持下去,我建议在可以的地方使用JPA,必须使用Hibernate(后面的部分使用JPA 2.0)。


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 ?

解决方案

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).

这篇关于差异Hibernate 3.5 / JPA 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆