我知道JPA 2是一个规范,Hibernate是ORM的工具。另外,我知道Hibernate比JPA 2有更多的特性。但从实际的角度来看,两者到底有什么区别呢?

我有使用iBatis的经验,现在我正在尝试学习Hibernate或JPA2。我拿起Pro JPA2书,它一直提到“JPA提供商”。例如:

如果你认为一个特性应该标准化,你应该说出来 并向您的JPA提供者请求它

这让我很困惑,所以我有几个问题:

仅使用JPA2,我可以通过简单地注释POJO从DB中获取数据 JPA2应该与“JPA提供者”一起使用吗?例如TopLink或Hibernate?如果是这样,那么与单独使用JPA2或单独使用Hibernate相比,使用JPA2 + Hibernate有什么好处? 你能推荐一本好的实用的JPA2书吗?“Pro JPA2”看起来更像是JPA2的圣经和参考书(直到本书的后半部分才进入查询)。有没有关于JPA2的问题/解决方法的书?


当前回答

JPA is JSR i.e. Java Specification Requirement to implement Object Relational Mapping which has got no specific code for its implementation. It defines certain set of rules for for accessing, persisting and managing the data between Java objects and the relational databaseWith its introduction, EJB was replaced as It was criticized for being heavyweight by the Java developer community. Hibernate is one of the way JPA can be implemented using te guidelines.Hibernate is a high-performance Object/Relational persistence and query service which is licensed under the open source GNU Lesser General Public License (LGPL) .The benefit of this is that you can swap out Hibernate's implementation of JPA for another implementation of the JPA specification. When you use straight Hibernate you are locking into the implementation because other ORMs may use different methods/configurations and annotations, therefore you cannot just switch over to another ORM.

其他回答

JPA是舞蹈,Hibernate是舞者。

JPA只是一个规范,而Hibernate是JPA提供者之一,即Hibernate实现了JPA合同中提到的各种事情。

Java——它不仅独立于操作系统,而且独立于供应商。

因此,您应该能够在不同的应用程序服务器上部署应用程序。 JPA是在任何Java EE兼容的应用服务器上实现的,它允许交换应用服务器,但是实现也会发生变化。Hibernate应用程序可能更容易部署在不同的应用程序服务器上。

形象地说,JPA只是接口,Hibernate/TopLink类(即接口实现)。

必须有接口实现才能使用接口。但是你可以通过接口使用类,即通过JPA API使用Hibernate,或者你可以直接使用实现,即直接使用Hibernate,而不是通过纯JPA API。

关于JPA的好书是Vlad Mihalcea的《高性能Java持久性》。

JPA是规范,Hibernate是遵循规范中规定的规则的实现提供者。