简体   繁体   English

Hibernate Native vs Hibernate JPA

[英]Hibernate Native vs Hibernate JPA

Hibernate website says there is a native Hibernate API as well as an implementation of JPA. Hibernate网站说有一个原生的Hibernate API以及一个JPA的实现。 What is the difference between the Native API and JPA implementation? Native API和JPA实现之间有什么区别? Advantages, disadvantages? 优点缺点?

I am working on a Spring MVC application, using Tomcat as the container, and MySQL for persistence. 我正在使用Spring MVC应用程序,使用Tomcat作为容器,使用MySQL进行持久化。 I've used Doctrine and Entity for PHP and .NET respectively in the past, using the code first approach. 我过去分别使用Doctrine和Entity for PHP和.NET,使用代码优先方法。 I would like to have something similar with Java. 我想有类似Java的东西。 I'm newer to Spring and never used Hibernate. 我是Spring的新手,从未使用过Hibernate。 My team would like to use an ORM and Hibernate seems to be the most popular. 我的团队想使用ORM,而Hibernate似乎是最受欢迎的。 We're not sure how Hibernate is going to workout or whether we should use native or JPA api. 我们不确定Hibernate将如何锻炼,或者我们是否应该使用原生或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. 我已经读过,使用JPA可以更容易地切换到另一个JPA实现,虽然我不知道是否需要它。

JPA is a standard for accessing relational databases through an object oriented API. JPA是通过面向对象的API访问关系数据库的标准。 Hibernate is an implementation of this API. Hibernate是此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. 当你想使用JPA时,你需要一些供应商来实现它,Hibernate是一个不错的选择,但还有其他像EclipseLink。

Hibernate exists longer than JPA. Hibernate的存在时间比JPA长。 The native, older API (which was a model for JPA) still exists, and sometimes it offers more possibilities than are exposed through JPA (eg orphan removal). 原生的旧API(JPA的模型)仍然存在,有时它提供的可能性比通过JPA暴露的更多(例如孤儿删除)。 If you need those you need to use the native API. 如果您需要那些,您需要使用本机API。 Using JPA has other merits, most important (in my opinion) more developers that know it. 使用JPA有其他优点,最重要的(在我看来)更多的开发人员知道它。 And you still can use some Hibernate specifics through configuration. 而你仍然可以通过配置使用一些Hibernate细节。

In general IMO it pays to use the standard API, here JPA, and do an experienced decision on the implementation to use. 一般而言,IMO支付使用标准API(此处为JPA),并对要使用的实现做出经验丰富的决定。

Most tutorials that use Hibernate natively are quite old - as is Hibernate 3, a pre-JPA release. 大多数本地使用Hibernate的教程都很老 - 就像Hibernate 3一样,这是一个JPA之前的版本。 While there are good reasons to use it, they (IMO) typically don't apply to the general audience. 虽然有充分的理由使用它,但它们(IMO)通常不适用于普通观众。 So if you are just beginning to learn in this field I would suggest to start with JPA. 所以如果你刚刚开始在这个领域学习,我建议从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. 但是目前官方的Hibernate文档将是一个良好的开端,就像寻找至少Hibernate 4的动态一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM