JPA和Hibernate有什么区别?

时间:2021-11-03 20:08:05

I understand that JPA 2 is a specification and Hibernate is a tool for ORM. Also, I understand that Hibernate has more features than JPA 2. But from a practical point of view, what really is the difference?

我理解JPA 2是一个规范,而Hibernate是ORM的一个工具。而且,我知道Hibernate比JPA 2有更多的特性。但是从实际的角度来看,真正的区别是什么?

I have experience using iBatis and now I'm trying to learn either Hibernate or JPA2. I picked up Pro JPA2 book and it keeps referring to "JPA provider". For example:

我有使用iBatis的经验,现在我正在尝试学习Hibernate或JPA2。我拿起专业的JPA2书,它一直指向“JPA provider”。例如:

If you think a feature should be standardized, you should speak up and request it from your JPA provider

如果您认为一个特性应该标准化,那么您应该大声说出来,并从您的JPA提供者请求它

This confuses me so I have a few questions:

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

  • Using JPA2 alone can I fetch data from DB by simply annotating my POJO's
  • 仅使用JPA2,我就可以通过对POJO的注释从DB中获取数据
  • Is JPA2 supposed to be used with a "JPA Provider" e.g TopLink or Hibernate? If so, then what's the benefit of using JPA2 + Hibernate as compared to JPA2 alone, or compared to Hibernate alone ?
  • JPA2应该与“JPA提供者”e一起使用。g TopLink或Hibernate)?如果是这样,那么使用JPA2 + Hibernate与单独使用JPA2或单独使用Hibernate相比有什么好处呢?
  • Can you recommend a good practical JPA2 book. "Pro JPA2" seems more like a bible and reference on JPA2 (It doesn't get into Queries until the later half of the book). Is there a book that takes a problem/solution approach to JPA2?
  • 你能推荐一本实用的JPA2书吗?“Pro JPA2”看起来更像是一本圣经和JPA2的参考(直到本书的后半部分才进入查询)。是否有一本书对JPA2采取了问题/解决方案的方法?

23 个解决方案

#1


777  

As you state JPA is just a specification, meaning there is no implementation. You can annotate your classes as much as you would like with JPA annotations, however without an implementation nothing will happen. Think of JPA as the guidelines that must be followed or an interface, while Hibernate's JPA implementation is code that meets the API as defined by the JPA specification and provides the under the hood functionality.

因为您的状态JPA只是一个规范,意味着没有实现。您可以在JPA注释中尽可能多地注释您的类,但是没有实现什么也不会发生。将JPA视为必须遵循的指导方针或接口,而Hibernate的JPA实现是符合JPA规范定义的API并提供hood功能下的代码。

When you use Hibernate with JPA you are actually using the Hibernate JPA implementation. 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时,实际上是在使用Hibernate JPA实现。这样做的好处是可以将Hibernate的JPA实现替换为JPA规范的另一个实现。当您使用直接Hibernate时,您将锁定到实现中,因为其他ORM可能使用不同的方法/配置和注释,因此您不能仅仅切换到另一个ORM。

For a more detailed description read my blog entry.

要获得更详细的描述,请阅读我的博客条目。

#2


634  

JPA is the dance, Hibernate is the dancer.

JPA是舞蹈,Hibernate是舞蹈。

#3


158  

Some things are too hard to understand without a historical perspective of the language and understanding of the JCP.

如果没有对语言的历史观点和对JCP的理解,有些事情是很难理解的。

Often there are third parties that develop packages that perform a function or fill a gap that are not part of the official JDK. For various reasons that function may become part of the Java JDK through the JCP (Java Community Process)

通常有第三方开发执行功能的包,或者填补正式JDK之外的空白。由于各种原因,该函数可能通过JCP (Java Community Process)成为Java JDK的一部分

Hibernate (in 2003) provided a way to abstract SQL and allow developers to think more in terms of persisting objects (ORM). You notify hibernate about your Entity objects and it automatically generates the strategy to persist them. Hibernate provided an implementation to do this and the API to drive the implementation either through XML config or annotations.

Hibernate(2003年)提供了一种抽象SQL的方法,允许开发人员从持久化对象(ORM)的角度考虑更多问题。您通知hibernate关于您的实体对象,它会自动生成策略来持久化它们。Hibernate提供了一个实现,API通过XML配置或注解来驱动实现。

The fundamental issue now is that your code becomes tightly coupled with a specific vendor(Hibernate) for what a lot of people thought should be more generic. Hence the need for a generic persistence API.

现在最基本的问题是,您的代码与特定的供应商(Hibernate)紧密耦合,许多人认为它应该更通用。因此需要一个通用的持久性API。

Meanwhile, the JCP with a lot of input from Hibernate and other ORM tool vendors was developing JSR 220 (Java Specification Request) which resulted in JPA 1.0 (2006) and eventually JSR 317 which is JPA 2.0 (2009). These are specifications of a generic Java Persistence API. The API is provided in the JDK as a set of interfaces so that your classes can depend on the javax.persistence and not worry about the particular vendor that is doing the work of persisting your objects. This is only the API and not the implementation. Hibernate now becomes one of the many vendors that implement the JPA 2.0 specification. You can code toward JPA and pick whatever compliant ORM vendor suits your needs.

与此同时,拥有Hibernate和其他ORM工具供应商大量输入的JCP正在开发JSR 220 (Java规范请求),这导致了JPA 1.0(2006)和最终的JSR 317(2009)。这些是通用Java持久性API的规范。JDK中提供了API作为一组接口,以便您的类可以依赖于javax。持久性,不要担心正在执行持久化对象工作的特定供应商。这只是API,而不是实现。Hibernate现在成为实现JPA 2.0规范的众多供应商之一。您可以针对JPA编写代码,并选择适合您需要的任何兼容ORM供应商。

There are cases where Hibernate may give you features that are not codified in JPA. In this case, you can choose to insert a Hibernate specific annotation directly in your class since JPA does not provide the interface to do that thing.

有些情况下,Hibernate可能会给您一些没有在JPA中编码的特性。在这种情况下,您可以选择直接在类中插入Hibernate特定的注释,因为JPA没有提供接口来实现这一点。

Source: http://www.reddit.com/r/java/comments/16ovek/understanding_when_to_use_jpa_vs_hibernate/

来源:http://www.reddit.com/r/java/comments/16ovek/understanding_when_to_use_jpa_vs_hibernate/

#4


100  

JPA is the interface while Hibernate is the implementation.

JPA是接口,而Hibernate是实现。

Traditionally there have been multiple Java ORM solutions:

传统上有多个Java ORM解决方案:

each implementation defining its own mapping definition or client API. The JPA expert group gathered the best of all these tools and so they created the Java Persistence API standard.

每个实现都定义自己的映射定义或客户端API。JPA专家组收集了所有这些工具中的精华,因此他们创建了Java持久性API标准。

A standard persistence API is very convenient from a client point of view, making it relatively easy to switch one implementation with the other (although in practice it's not that simple because on large projects you'll have to use specific non-standard features anyway).

从客户端的角度来看,标准的持久性API非常方便,因此相对容易地将一个实现与另一个实现进行切换(尽管在实践中它并不是那么简单,因为在大型项目中,您必须使用特定的非标准特性)。

The standard JPA has pushed Java ORM competition to a new level and this can only lead to better implementations.

标准的JPA将Java ORM竞争推到了一个新的水平,这只会带来更好的实现。

As explained in my book, High-Performance Java Persistence, Hibernate offers features that are not yet supported by JPA:

正如在我的书中所解释的,高性能Java持久性,Hibernate提供了JPA还没有支持的特性:

  • extended identifier generators (hi/lo, pooled, pooled-lo)
  • 扩展标识符生成器(hi/lo、pooled、pooled-lo)
  • transparent prepared statement batching
  • 透明的事先准备好的声明中批处理
  • customizable CRUD (@SQLInsert, @SQLUpdate, @SQLDelete) statements
  • 可自定义CRUD (@SQLInsert, @SQLUpdate, @SQLDelete)语句
  • static or dynamic collection filters (e.g. @FilterDef, @Filter, @Where) and entity filters (e.g. @Where)
  • 静态或动态的收集过滤器(例如@FilterDef, @Filter, @Where)和实体过滤器(例如@Where)
  • mapping properties to SQL fragments (e.g. @Formula)
  • 将属性映射到SQL片段(例如@Formula)
  • immutable entities (e.g. @Immutable)
  • 不变的实体(例如@ immutable)
  • more flush modes (e.g. FlushMode.MANUAL, FlushMode.ALWAYS)
  • 更多的刷新模式(如FlushMode)。手册,FlushMode.ALWAYS)
  • querying the second-level cache by the natural key of a given entity
  • 通过给定实体的自然键查询二级缓存
  • entity-level cache concurrency strategies (e.g. Cache(usage = CacheConcurrencyStrategy.READ_WRITE))
  • 实体级缓存并发策略(例如,缓存(usage = CacheConcurrencyStrategy.READ_WRITE))
  • versioned bulk updates through HQL
  • 通过HQL版本化批量更新
  • exclude fields from optimistic locking check (e.g. @OptimisticLock(excluded = true))
  • 排除来自乐观锁定检查的字段(例如@OptimisticLock(排除= true))
  • versionless optimistic locking (e.g. OptimisticLockType.ALL, OptimisticLockType.DIRTY)
  • 无版本乐观锁(例如OptimisticLockType)。所有OptimisticLockType.DIRTY)
  • support for skipping (without waiting) pessimistic lock requests
  • 支持跳过(不等待)悲观锁请求
  • support for Java 8 Date and Time
  • 支持Java 8日期和时间
  • support for multitenancy
  • 支持多租户
  • support for soft delete (e.g. @Where, @Filter)
  • 支持软删除(例如@Where, @Filter)

These extra features allow Hibernate to address many persistence requirements demanded by large enterprise applications.

这些额外的特性使Hibernate能够满足大型企业应用程序所需的许多持久性需求。

#5


58  

From the Wiki.

从Wiki。

Motivation for creating the Java Persistence API

创建Java Persistence API的动机。

Many enterprise Java developers use lightweight persistent objects provided by open-source frameworks or Data Access Objects instead of entity beans: entity beans and enterprise beans had a reputation of being too heavyweight and complicated, and one could only use them in Java EE application servers. Many of the features of the third-party persistence frameworks were incorporated into the Java Persistence API, and as of 2006 projects like Hibernate (version 3.2) and Open-Source Version TopLink Essentials have become implementations of the Java Persistence API.

许多企业Java开发人员使用开源框架或数据访问对象提供的轻量级持久对象,而不是实体bean:实体bean和企业bean被认为太过重量级和复杂,并且只能在Java EE应用服务器中使用它们。第三方持久性框架的许多特性被集成到Java持久性API中,到2006年Hibernate(版本3.2)和开放源码版本TopLink Essentials软件包等项目已经成为Java持久性API的实现。

As told in the JCP page the Eclipse link is the Reference Implementation for JPA. Have look at this answer for bit more on this.

如JCP页面中所述,Eclipse链接是JPA的引用实现。我们来看看这个答案。

JPA itself has features that will make up for a standard ORM framework. Since JPA is a part of Java EE spec, you can use JPA alone in a project and it should work with any Java EE compatible Servers. Yes, these servers will have the implementations for the JPA spec.

JPA本身有一些特性可以弥补标准ORM框架的不足。由于JPA是Java EE规范的一部分,您可以在项目中单独使用JPA,并且它应该与任何Java EE兼容的服务器一起工作。是的,这些服务器将具有JPA规范的实现。

Hibernate is the most popular ORM framework, once the JPA got introduced hibernate conforms to the JPA specifications. Apart from the basic set of specification that it should follow hibernate provides whole lot of additional stuff.

Hibernate是最流行的ORM框架,一旦JPA引入Hibernate就符合JPA规范。除了应该遵循hibernate的基本规范之外,它还提供了大量的附加内容。

#6


20  

Hibernate is a JPA provider.

Hibernate是一个JPA提供者。

The page JPA Vs Hibernate by Krishna Srinivasan says:

Krishna Srinivasan的页面JPA Vs Hibernate说:

JPA is a specification for accessing, persisting and managing the data between Java objects and the relational database. As the definition says its API, it is only the specification. There is no implementation for the API. JPA specifies the set of rules and guidelines for developing the interfaces that follows standard. Straight to the point : JPA is just guidelines to implement the Object Relational Mapping (ORM) and there is no underlying code for the implementation. Where as, Hibernate is the actual implementation of JPA guidelines. When hibernate implements the JPA specification, this will be certified by the JPA group upon following all the standards mentioned in the specification. For example, JPA guidelines would provide information of mandatory and optional features to be implemented as part of the JPA implementation.

JPA是访问、持久化和管理Java对象和关系数据库之间的数据的规范。正如定义所说的API,它只是规范。API没有实现。JPA为开发遵循标准的接口指定了一组规则和指导原则。直截了当地说:JPA只是实现对象关系映射(ORM)的指导方针,并且没有实现的底层代码。其中,Hibernate是JPA指南的实际实现。当hibernate实现JPA规范时,在遵循规范中提到的所有标准之后,JPA组将对其进行认证。例如,JPA指导方针将提供作为JPA实现的一部分要实现的强制性和可选特性的信息。

#7


16  

JPA is just a specification which needs concrete implementation. The default implementation oracle provide is "Eclipselink" now. (Toplink is donated by Oracle to Eclipse foundation to merge with eclipselink)

JPA只是一个需要具体实现的规范。oracle提供的默认实现是“Eclipselink”。(Toplink由Oracle捐赠给Eclipse foundation以与eclipselink合并)

(Reference : http://www.oracle.com/technetwork/middleware/toplink/index-085257.html http://www.eclipse.org/org/press-release/20080317_Eclipselink.php )

(参考:http://www.oracle.com/technet/middleware/toplink/index -085257.html http://www.eclipse.org/press-release/20080317_eclipselink.php)

Using Eclipselink, one can be sure that the code is portable to any implementation if need arises. Hibernate is also a full JPA implementation + MORE ( Sort of JPA Plus). Hibernate is super set of JPA with some extra Hibernate specific functionality. So app developed in Hibernate may not be compatible when switched to other implementation. Still hibernate is choice of majority of developers as JPA implementation and widely used.

使用Eclipselink,您可以确保在需要时代码可以移植到任何实现。Hibernate也是一个完整的JPA实现+ MORE(有点像JPA Plus)。Hibernate是JPA的超级集合,带有一些特定于Hibernate的功能。因此,在Hibernate中开发的应用程序在切换到其他实现时可能不兼容。不过,大多数开发人员选择hibernate作为JPA实现并广泛使用。

Another JPA implementation is OpenJPA (openjpa.apache.org) which is an extension of Kodo implementation.

另一个JPA实现是OpenJPA (openjpa.apache.org),它是Kodo实现的扩展。

#8


15  

JPA : is just like an interface and have no concrete implementation of it to use functions which are there in JPA.

JPA:就像一个接口,没有具体的实现来使用JPA中存在的函数。

Hibernate : is just a JPA Provider which have the implementation of the functions in JPA and can have some extra functions which might not be there in JPA.

Hibernate:只是一个JPA提供者,它具有JPA中的函数实现,并且可以有一些在JPA中可能不存在的额外函数。

TIP : you can use

提示:你可以用

     *combo 1* : JPA + JPA Provider(Hibernate) 
     *combo 2* : only Hiberante which does not need any interface 

Combo 1 : is used when you feel that your hibernate is not giving better performance and want to change JPA Provider that time you don't have to write your JPA once again. You can write another JPA Provider ... and can change as many times you can.

组合1:当您觉得您的hibernate没有提供更好的性能并希望在不必再次编写JPA时更改JPA提供程序时使用。您可以编写另一个JPA提供者…你可以改变很多次。

Combo 2 : is used very less as when you are not going change your JPA Provider at any cost.

当您不打算以任何代价更改您的JPA提供程序时,使用组合2:非常少。

Visit http://blog-tothought.rhcloud.com//post/2, where your complete confusion will get clear.

访问http://blog.t.rhcloud.com//post/2,您的混乱将会变得清晰。

#9


11  

JPA is the interface, Hibernate is one implementation of that interface.

JPA是接口,Hibernate是该接口的一个实现。

#10


10  

JPA is a specification to standardize ORM-APIs. Hibernate is a vendor of a JPA implementation. So if you use JPA with hibernate, you can use the standard JPA API, hibernate will be under the hood, offering some more non standard functions. See http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html_single/ and http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/

JPA是标准化orm - api的规范。Hibernate是JPA实现的供应商。因此,如果您在hibernate中使用JPA,您可以使用标准的JPA API, hibernate将会在底层,提供更多的非标准函数。看到http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html_single/和http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/

#11


5  

JPA is just a specification.In market there are many vendors which implements JPA. Different types of vendors implement JPA in different way. so different types of vendors provide different functionality so choose proper vendor based on your requirements.

JPA只是一个规范。市场上有很多实现JPA的供应商。不同类型的供应商以不同的方式实现JPA。因此,不同类型的供应商提供了不同的功能,因此根据您的需求选择合适的供应商。

If you are using Hibernate or any other vendors instead of JPA than you can not easily move to hibernate to EclipseLink or OpenJPA to Hibernate.But If you using JPA than you just have to change provide in persistence XML file.So migration is easily possible in JPA.

如果您正在使用Hibernate或任何其他供应商而不是JPA,那么您不能轻松地将Hibernate迁移到EclipseLink或OpenJPA以Hibernate。但是如果您使用的是JPA,那么您只需在持久性XML文件中更改提供。因此,在JPA中迁移是很容易实现的。

#12


4  

JPA is an API, one which Hibernate implements.Hibernate predates JPA. Before JPA, you write native hibernate code to do your ORM. JPA is just the interface, so now you write JPA code and you need to find an implementation. Hibernate happens to be an implementation.

JPA是一个API,一个Hibernate实现的API。Hibernate早于JPA。在JPA之前,您编写本机hibernate代码来执行ORM。JPA只是一个接口,所以现在您要编写JPA代码,并且需要找到一个实现。Hibernate恰好是一个实现。

So your choices are this: hibernate, toplink, etc...

所以你的选择是:hibernate, toplink等等…

The advantage to JPA is that it allows you to swap out your implementation if need be. The disadvantage is that the native hibernate/toplink/etc... API may offer functionality that the JPA specification doesn't support.

JPA的优点是,如果需要,它允许您交换实现。缺点是本机hibernate/toplink等…API可能提供JPA规范不支持的功能。

#13


4  

While JPA is the specification, Hibernate is the implementation provider that follows the rules dictated in the specification.

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

#14


3  

Java - its independence is not only from the operating system, but also from the vendor.

Java -它的独立性不仅来自操作系统,而且来自供应商。

Therefore, you should be able to deploy your application on different application servers. JPA is implemented in any Java EE- compliant application server and it allows to swap application servers, but then the implementation is also changing. A Hibernate application may be easier to deploy on a different application server.

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

#15


3  

JPA is a specification that you implement in your data layer to perform db opertations, OR mappings and other required tasks.

JPA是您在数据层中实现的一个规范,用于执行db操作、映射和其他必需的任务。

Since it is just a specification, you need a tool to have it implemented. That tool can be either Hibernate, TopLink, iBatis, spring-data etc.

因为它只是一个规范,您需要一个工具来实现它。该工具可以是Hibernate、TopLink、iBatis、spring-data等。

You don't necessarily require JPA if you are using Hibernate in your Data Layer. But if you use JPA specification for Hibernate, then it will make switching to other ORM tools like iBatis, TopLink easy in future, because the specification is common for others as well.

如果在数据层中使用Hibernate,则不一定需要JPA。但是,如果您为Hibernate使用JPA规范,那么它将使切换到其他ORM工具(如iBatis、TopLink)变得更加容易,因为该规范对其他人也很常见。

*(if you remember, you do import javax.persistence.*; when you use annotations for OR mapping (like @Id, @Column, @GeneratedValue etc.) in Hibernate, that's where you are using JPA under Hibernate, you can use JPA's @Query & other features as well)

*(如果您记得的话,您确实导入了javax.persistence.*;当您在Hibernate中使用注释或映射(比如@Id、@Column、@GeneratedValue等)时,您就可以在Hibernate中使用JPA,您也可以使用JPA的@Query和其他特性)

#16


2  

JPA is a Java API specification which describes the management of relational data in applications using Java Platform. where as Hibernate is a ORM (Object Relational Mapping) library which follows JPA specification.

JPA是一个Java API规范,它描述了使用Java平台的应用程序中关系数据的管理。其中Hibernate是遵循JPA规范的ORM(对象关系映射)库。

You can think JPA as a set of Rules which is implemented by Hibernate.

您可以将JPA视为由Hibernate实现的一组规则。

#17


2  

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是JSR,即实现对象关系映射的Java规范要求,它的实现没有特定的代码。它定义了访问、持久化和管理Java对象和关系数据库之间的数据的一组规则。Hibernate是使用te指南实现JPA的方法之一。Hibernate是一个高性能的对象/关系持久性和查询服务,它是在开源的GNU通用公共许可证(LGPL)下授权的,其好处是您可以将Hibernate的JPA实现替换为JPA规范的另一个实现。当您使用直接Hibernate时,您将锁定到实现中,因为其他ORM可能使用不同的方法/配置和注释,因此您不能仅仅切换到另一个ORM。

#18


1  

JPA is just a specification which needs concrete implementation. The default implementation provided by oracle is "Eclipselink" now. Toplink is donated by Oracle to Eclipse foundation to merge with eclipselink.

JPA只是一个需要具体实现的规范。oracle提供的默认实现是“Eclipselink”。Toplink由Oracle捐赠给Eclipse foundation以与eclipselink合并。

Using Eclipselink, one can be sure that the code is portable to any implementation if need arises. Hibernate is also a full JPA implementation + MORE. Hibernate is super set of JPA with some extra Hibernate specific functionality. So application developed in Hibernate may not be compatible when switched to other implementation. Still hibernate is choice of majority of developers as JPA implementation and widely used.

使用Eclipselink,您可以确保在需要时代码可以移植到任何实现。Hibernate也是一个完整的JPA实现+更多。Hibernate是JPA的超级集合,带有一些特定于Hibernate的功能。因此,在Hibernate中开发的应用程序在切换到其他实现时可能不兼容。不过,大多数开发人员选择hibernate作为JPA实现并广泛使用。

Another JPA implementation is OpenJPA, which is an extension of Kodo implementation.

另一个JPA实现是OpenJPA,它是Kodo实现的扩展。

JPA vs Hibernate

JPA vs冬眠

#19


1  

I try to explain in very easy words.

Suppose you need a car as we all know their are several A class manufacturer like MERCEDES, BMW , AUDI etc.

假设你需要一辆车,因为我们都知道他们有好几个一流的制造商,像奔驰,宝马,奥迪等等。

Now in above statement CAR(is a specification) as every car have common features like thing with 4 wheels and can be driven on road is car...so its like JPA. And MERCEDES, BMW , AUDI etc are just using common car feature and adding functionality according to their customer base so they are implementing the car specification like hibernate , iBATIS etc.

现在在上面的声明汽车(是一种规格),因为每辆车都有共同的特点,比如有4个*,可以在路上行驶的是汽车……所以它像JPA。奔驰、宝马、奥迪等都只是使用普通的汽车功能,并根据客户的需求增加功能,所以他们正在实现hibernate、iBATIS等汽车规格。

So by this common features goes to jpa and hibernate is just an implementation according to their jboss need.

因此,通过这些常见的特性,hibernate只是根据jboss的需要实现的。

1 more thing

JPA includes some basic properties so in future if you want to change hibernate to any other implementation you can easily switch without much headache and for those basic properties includes JPA annotations which can work for any implementation technology, JPQL queries.

JPA包含一些基本的属性,因此将来如果您想要将hibernate更改为任何其他实现,您可以轻松切换,而对于这些基本属性,JPA注释可以用于任何实现技术,JPQL查询。

So mainly we implement hibernate with JPA type technology just for in case we want to switch our implementation according to client need plus you will write less code as some common features are involved in JPA. If someone still not clear then you can comment as i m new on stack overflow.

因此,我们主要使用JPA类型技术实现hibernate,如果我们想要根据客户需求来切换我们的实现,那么您将编写更少的代码,因为一些常见的特性涉及到JPA。如果有人仍然不清楚,那么你可以评论我是新的关于栈溢出。

Thank you

#20


0  

JPA is just a specification while Hibernate is one of the JPA provider i.e hibernate is implementing various things mentioned in JPA contract.

JPA只是一个规范,而Hibernate是JPA提供者之一。e hibernate实现了JPA契约中提到的各种功能。

#21


0  

JPA or Java Persistence API is a standard specification for ORM implementations whereas Hibernate is the actual ORM implementation or framework.

JPA或Java持久性API是ORM实现的标准规范,而Hibernate是实际的ORM实现或框架。

#22


-1  

JPA is Java Persistence API. Which Specifies only the specifications for APIs. Means that the set of rules and guidelines for creating the APIs. If says another context, It is set of standards which provides the wrapper for creating those APIs , can be use for accessing entity object from database. JPA is provided by oracle.When we are going to do database access , we definitely needs its implementation. Means JPA specifies only guidelines for implementing APIs. Hibernate is a JPA provider/Vendor who responsible for implementing that APIs. Like Hibernate TopLink and Open JPA is some of examples of JPA API providers. So we uses JPA specified standard APIs through hibernate.

JPA是Java持久性API。它只指定api的规范。意味着创建api的规则和指导原则的集合。如果说另一个上下文,它是一组标准,为创建这些api提供包装器,可以用于从数据库访问实体对象。JPA由oracle提供。当我们要进行数据库访问时,我们肯定需要它的实现。意味着JPA只指定实现api的指导方针。Hibernate是一个JPA提供者/供应商,负责实现那些api。与Hibernate TopLink和Open JPA一样,JPA API提供程序也有一些例子。因此,我们通过hibernate使用JPA指定的标准api。

#23


-2  

Figuratively speaking JPA is just interface, Hibernate/TopLink - class (i.e. interface implementation).

打个比方,JPA只是接口、Hibernate/TopLink - class(即接口实现)。

You must have interface implementation to use interface. But you can use class through interface, i.e. Use Hibernate through JPA API or you can use implementation directly, i.e. use Hibernate directly, not through pure JPA API.

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

Good book about JPA is "High-Performance Java Persistence" of Vlad Mihalcea.

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

#1


777  

As you state JPA is just a specification, meaning there is no implementation. You can annotate your classes as much as you would like with JPA annotations, however without an implementation nothing will happen. Think of JPA as the guidelines that must be followed or an interface, while Hibernate's JPA implementation is code that meets the API as defined by the JPA specification and provides the under the hood functionality.

因为您的状态JPA只是一个规范,意味着没有实现。您可以在JPA注释中尽可能多地注释您的类,但是没有实现什么也不会发生。将JPA视为必须遵循的指导方针或接口,而Hibernate的JPA实现是符合JPA规范定义的API并提供hood功能下的代码。

When you use Hibernate with JPA you are actually using the Hibernate JPA implementation. 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时,实际上是在使用Hibernate JPA实现。这样做的好处是可以将Hibernate的JPA实现替换为JPA规范的另一个实现。当您使用直接Hibernate时,您将锁定到实现中,因为其他ORM可能使用不同的方法/配置和注释,因此您不能仅仅切换到另一个ORM。

For a more detailed description read my blog entry.

要获得更详细的描述,请阅读我的博客条目。

#2


634  

JPA is the dance, Hibernate is the dancer.

JPA是舞蹈,Hibernate是舞蹈。

#3


158  

Some things are too hard to understand without a historical perspective of the language and understanding of the JCP.

如果没有对语言的历史观点和对JCP的理解,有些事情是很难理解的。

Often there are third parties that develop packages that perform a function or fill a gap that are not part of the official JDK. For various reasons that function may become part of the Java JDK through the JCP (Java Community Process)

通常有第三方开发执行功能的包,或者填补正式JDK之外的空白。由于各种原因,该函数可能通过JCP (Java Community Process)成为Java JDK的一部分

Hibernate (in 2003) provided a way to abstract SQL and allow developers to think more in terms of persisting objects (ORM). You notify hibernate about your Entity objects and it automatically generates the strategy to persist them. Hibernate provided an implementation to do this and the API to drive the implementation either through XML config or annotations.

Hibernate(2003年)提供了一种抽象SQL的方法,允许开发人员从持久化对象(ORM)的角度考虑更多问题。您通知hibernate关于您的实体对象,它会自动生成策略来持久化它们。Hibernate提供了一个实现,API通过XML配置或注解来驱动实现。

The fundamental issue now is that your code becomes tightly coupled with a specific vendor(Hibernate) for what a lot of people thought should be more generic. Hence the need for a generic persistence API.

现在最基本的问题是,您的代码与特定的供应商(Hibernate)紧密耦合,许多人认为它应该更通用。因此需要一个通用的持久性API。

Meanwhile, the JCP with a lot of input from Hibernate and other ORM tool vendors was developing JSR 220 (Java Specification Request) which resulted in JPA 1.0 (2006) and eventually JSR 317 which is JPA 2.0 (2009). These are specifications of a generic Java Persistence API. The API is provided in the JDK as a set of interfaces so that your classes can depend on the javax.persistence and not worry about the particular vendor that is doing the work of persisting your objects. This is only the API and not the implementation. Hibernate now becomes one of the many vendors that implement the JPA 2.0 specification. You can code toward JPA and pick whatever compliant ORM vendor suits your needs.

与此同时,拥有Hibernate和其他ORM工具供应商大量输入的JCP正在开发JSR 220 (Java规范请求),这导致了JPA 1.0(2006)和最终的JSR 317(2009)。这些是通用Java持久性API的规范。JDK中提供了API作为一组接口,以便您的类可以依赖于javax。持久性,不要担心正在执行持久化对象工作的特定供应商。这只是API,而不是实现。Hibernate现在成为实现JPA 2.0规范的众多供应商之一。您可以针对JPA编写代码,并选择适合您需要的任何兼容ORM供应商。

There are cases where Hibernate may give you features that are not codified in JPA. In this case, you can choose to insert a Hibernate specific annotation directly in your class since JPA does not provide the interface to do that thing.

有些情况下,Hibernate可能会给您一些没有在JPA中编码的特性。在这种情况下,您可以选择直接在类中插入Hibernate特定的注释,因为JPA没有提供接口来实现这一点。

Source: http://www.reddit.com/r/java/comments/16ovek/understanding_when_to_use_jpa_vs_hibernate/

来源:http://www.reddit.com/r/java/comments/16ovek/understanding_when_to_use_jpa_vs_hibernate/

#4


100  

JPA is the interface while Hibernate is the implementation.

JPA是接口,而Hibernate是实现。

Traditionally there have been multiple Java ORM solutions:

传统上有多个Java ORM解决方案:

each implementation defining its own mapping definition or client API. The JPA expert group gathered the best of all these tools and so they created the Java Persistence API standard.

每个实现都定义自己的映射定义或客户端API。JPA专家组收集了所有这些工具中的精华,因此他们创建了Java持久性API标准。

A standard persistence API is very convenient from a client point of view, making it relatively easy to switch one implementation with the other (although in practice it's not that simple because on large projects you'll have to use specific non-standard features anyway).

从客户端的角度来看,标准的持久性API非常方便,因此相对容易地将一个实现与另一个实现进行切换(尽管在实践中它并不是那么简单,因为在大型项目中,您必须使用特定的非标准特性)。

The standard JPA has pushed Java ORM competition to a new level and this can only lead to better implementations.

标准的JPA将Java ORM竞争推到了一个新的水平,这只会带来更好的实现。

As explained in my book, High-Performance Java Persistence, Hibernate offers features that are not yet supported by JPA:

正如在我的书中所解释的,高性能Java持久性,Hibernate提供了JPA还没有支持的特性:

  • extended identifier generators (hi/lo, pooled, pooled-lo)
  • 扩展标识符生成器(hi/lo、pooled、pooled-lo)
  • transparent prepared statement batching
  • 透明的事先准备好的声明中批处理
  • customizable CRUD (@SQLInsert, @SQLUpdate, @SQLDelete) statements
  • 可自定义CRUD (@SQLInsert, @SQLUpdate, @SQLDelete)语句
  • static or dynamic collection filters (e.g. @FilterDef, @Filter, @Where) and entity filters (e.g. @Where)
  • 静态或动态的收集过滤器(例如@FilterDef, @Filter, @Where)和实体过滤器(例如@Where)
  • mapping properties to SQL fragments (e.g. @Formula)
  • 将属性映射到SQL片段(例如@Formula)
  • immutable entities (e.g. @Immutable)
  • 不变的实体(例如@ immutable)
  • more flush modes (e.g. FlushMode.MANUAL, FlushMode.ALWAYS)
  • 更多的刷新模式(如FlushMode)。手册,FlushMode.ALWAYS)
  • querying the second-level cache by the natural key of a given entity
  • 通过给定实体的自然键查询二级缓存
  • entity-level cache concurrency strategies (e.g. Cache(usage = CacheConcurrencyStrategy.READ_WRITE))
  • 实体级缓存并发策略(例如,缓存(usage = CacheConcurrencyStrategy.READ_WRITE))
  • versioned bulk updates through HQL
  • 通过HQL版本化批量更新
  • exclude fields from optimistic locking check (e.g. @OptimisticLock(excluded = true))
  • 排除来自乐观锁定检查的字段(例如@OptimisticLock(排除= true))
  • versionless optimistic locking (e.g. OptimisticLockType.ALL, OptimisticLockType.DIRTY)
  • 无版本乐观锁(例如OptimisticLockType)。所有OptimisticLockType.DIRTY)
  • support for skipping (without waiting) pessimistic lock requests
  • 支持跳过(不等待)悲观锁请求
  • support for Java 8 Date and Time
  • 支持Java 8日期和时间
  • support for multitenancy
  • 支持多租户
  • support for soft delete (e.g. @Where, @Filter)
  • 支持软删除(例如@Where, @Filter)

These extra features allow Hibernate to address many persistence requirements demanded by large enterprise applications.

这些额外的特性使Hibernate能够满足大型企业应用程序所需的许多持久性需求。

#5


58  

From the Wiki.

从Wiki。

Motivation for creating the Java Persistence API

创建Java Persistence API的动机。

Many enterprise Java developers use lightweight persistent objects provided by open-source frameworks or Data Access Objects instead of entity beans: entity beans and enterprise beans had a reputation of being too heavyweight and complicated, and one could only use them in Java EE application servers. Many of the features of the third-party persistence frameworks were incorporated into the Java Persistence API, and as of 2006 projects like Hibernate (version 3.2) and Open-Source Version TopLink Essentials have become implementations of the Java Persistence API.

许多企业Java开发人员使用开源框架或数据访问对象提供的轻量级持久对象,而不是实体bean:实体bean和企业bean被认为太过重量级和复杂,并且只能在Java EE应用服务器中使用它们。第三方持久性框架的许多特性被集成到Java持久性API中,到2006年Hibernate(版本3.2)和开放源码版本TopLink Essentials软件包等项目已经成为Java持久性API的实现。

As told in the JCP page the Eclipse link is the Reference Implementation for JPA. Have look at this answer for bit more on this.

如JCP页面中所述,Eclipse链接是JPA的引用实现。我们来看看这个答案。

JPA itself has features that will make up for a standard ORM framework. Since JPA is a part of Java EE spec, you can use JPA alone in a project and it should work with any Java EE compatible Servers. Yes, these servers will have the implementations for the JPA spec.

JPA本身有一些特性可以弥补标准ORM框架的不足。由于JPA是Java EE规范的一部分,您可以在项目中单独使用JPA,并且它应该与任何Java EE兼容的服务器一起工作。是的,这些服务器将具有JPA规范的实现。

Hibernate is the most popular ORM framework, once the JPA got introduced hibernate conforms to the JPA specifications. Apart from the basic set of specification that it should follow hibernate provides whole lot of additional stuff.

Hibernate是最流行的ORM框架,一旦JPA引入Hibernate就符合JPA规范。除了应该遵循hibernate的基本规范之外,它还提供了大量的附加内容。

#6


20  

Hibernate is a JPA provider.

Hibernate是一个JPA提供者。

The page JPA Vs Hibernate by Krishna Srinivasan says:

Krishna Srinivasan的页面JPA Vs Hibernate说:

JPA is a specification for accessing, persisting and managing the data between Java objects and the relational database. As the definition says its API, it is only the specification. There is no implementation for the API. JPA specifies the set of rules and guidelines for developing the interfaces that follows standard. Straight to the point : JPA is just guidelines to implement the Object Relational Mapping (ORM) and there is no underlying code for the implementation. Where as, Hibernate is the actual implementation of JPA guidelines. When hibernate implements the JPA specification, this will be certified by the JPA group upon following all the standards mentioned in the specification. For example, JPA guidelines would provide information of mandatory and optional features to be implemented as part of the JPA implementation.

JPA是访问、持久化和管理Java对象和关系数据库之间的数据的规范。正如定义所说的API,它只是规范。API没有实现。JPA为开发遵循标准的接口指定了一组规则和指导原则。直截了当地说:JPA只是实现对象关系映射(ORM)的指导方针,并且没有实现的底层代码。其中,Hibernate是JPA指南的实际实现。当hibernate实现JPA规范时,在遵循规范中提到的所有标准之后,JPA组将对其进行认证。例如,JPA指导方针将提供作为JPA实现的一部分要实现的强制性和可选特性的信息。

#7


16  

JPA is just a specification which needs concrete implementation. The default implementation oracle provide is "Eclipselink" now. (Toplink is donated by Oracle to Eclipse foundation to merge with eclipselink)

JPA只是一个需要具体实现的规范。oracle提供的默认实现是“Eclipselink”。(Toplink由Oracle捐赠给Eclipse foundation以与eclipselink合并)

(Reference : http://www.oracle.com/technetwork/middleware/toplink/index-085257.html http://www.eclipse.org/org/press-release/20080317_Eclipselink.php )

(参考:http://www.oracle.com/technet/middleware/toplink/index -085257.html http://www.eclipse.org/press-release/20080317_eclipselink.php)

Using Eclipselink, one can be sure that the code is portable to any implementation if need arises. Hibernate is also a full JPA implementation + MORE ( Sort of JPA Plus). Hibernate is super set of JPA with some extra Hibernate specific functionality. So app developed in Hibernate may not be compatible when switched to other implementation. Still hibernate is choice of majority of developers as JPA implementation and widely used.

使用Eclipselink,您可以确保在需要时代码可以移植到任何实现。Hibernate也是一个完整的JPA实现+ MORE(有点像JPA Plus)。Hibernate是JPA的超级集合,带有一些特定于Hibernate的功能。因此,在Hibernate中开发的应用程序在切换到其他实现时可能不兼容。不过,大多数开发人员选择hibernate作为JPA实现并广泛使用。

Another JPA implementation is OpenJPA (openjpa.apache.org) which is an extension of Kodo implementation.

另一个JPA实现是OpenJPA (openjpa.apache.org),它是Kodo实现的扩展。

#8


15  

JPA : is just like an interface and have no concrete implementation of it to use functions which are there in JPA.

JPA:就像一个接口,没有具体的实现来使用JPA中存在的函数。

Hibernate : is just a JPA Provider which have the implementation of the functions in JPA and can have some extra functions which might not be there in JPA.

Hibernate:只是一个JPA提供者,它具有JPA中的函数实现,并且可以有一些在JPA中可能不存在的额外函数。

TIP : you can use

提示:你可以用

     *combo 1* : JPA + JPA Provider(Hibernate) 
     *combo 2* : only Hiberante which does not need any interface 

Combo 1 : is used when you feel that your hibernate is not giving better performance and want to change JPA Provider that time you don't have to write your JPA once again. You can write another JPA Provider ... and can change as many times you can.

组合1:当您觉得您的hibernate没有提供更好的性能并希望在不必再次编写JPA时更改JPA提供程序时使用。您可以编写另一个JPA提供者…你可以改变很多次。

Combo 2 : is used very less as when you are not going change your JPA Provider at any cost.

当您不打算以任何代价更改您的JPA提供程序时,使用组合2:非常少。

Visit http://blog-tothought.rhcloud.com//post/2, where your complete confusion will get clear.

访问http://blog.t.rhcloud.com//post/2,您的混乱将会变得清晰。

#9


11  

JPA is the interface, Hibernate is one implementation of that interface.

JPA是接口,Hibernate是该接口的一个实现。

#10


10  

JPA is a specification to standardize ORM-APIs. Hibernate is a vendor of a JPA implementation. So if you use JPA with hibernate, you can use the standard JPA API, hibernate will be under the hood, offering some more non standard functions. See http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html_single/ and http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/

JPA是标准化orm - api的规范。Hibernate是JPA实现的供应商。因此,如果您在hibernate中使用JPA,您可以使用标准的JPA API, hibernate将会在底层,提供更多的非标准函数。看到http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html_single/和http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/

#11


5  

JPA is just a specification.In market there are many vendors which implements JPA. Different types of vendors implement JPA in different way. so different types of vendors provide different functionality so choose proper vendor based on your requirements.

JPA只是一个规范。市场上有很多实现JPA的供应商。不同类型的供应商以不同的方式实现JPA。因此,不同类型的供应商提供了不同的功能,因此根据您的需求选择合适的供应商。

If you are using Hibernate or any other vendors instead of JPA than you can not easily move to hibernate to EclipseLink or OpenJPA to Hibernate.But If you using JPA than you just have to change provide in persistence XML file.So migration is easily possible in JPA.

如果您正在使用Hibernate或任何其他供应商而不是JPA,那么您不能轻松地将Hibernate迁移到EclipseLink或OpenJPA以Hibernate。但是如果您使用的是JPA,那么您只需在持久性XML文件中更改提供。因此,在JPA中迁移是很容易实现的。

#12


4  

JPA is an API, one which Hibernate implements.Hibernate predates JPA. Before JPA, you write native hibernate code to do your ORM. JPA is just the interface, so now you write JPA code and you need to find an implementation. Hibernate happens to be an implementation.

JPA是一个API,一个Hibernate实现的API。Hibernate早于JPA。在JPA之前,您编写本机hibernate代码来执行ORM。JPA只是一个接口,所以现在您要编写JPA代码,并且需要找到一个实现。Hibernate恰好是一个实现。

So your choices are this: hibernate, toplink, etc...

所以你的选择是:hibernate, toplink等等…

The advantage to JPA is that it allows you to swap out your implementation if need be. The disadvantage is that the native hibernate/toplink/etc... API may offer functionality that the JPA specification doesn't support.

JPA的优点是,如果需要,它允许您交换实现。缺点是本机hibernate/toplink等…API可能提供JPA规范不支持的功能。

#13


4  

While JPA is the specification, Hibernate is the implementation provider that follows the rules dictated in the specification.

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

#14


3  

Java - its independence is not only from the operating system, but also from the vendor.

Java -它的独立性不仅来自操作系统,而且来自供应商。

Therefore, you should be able to deploy your application on different application servers. JPA is implemented in any Java EE- compliant application server and it allows to swap application servers, but then the implementation is also changing. A Hibernate application may be easier to deploy on a different application server.

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

#15


3  

JPA is a specification that you implement in your data layer to perform db opertations, OR mappings and other required tasks.

JPA是您在数据层中实现的一个规范,用于执行db操作、映射和其他必需的任务。

Since it is just a specification, you need a tool to have it implemented. That tool can be either Hibernate, TopLink, iBatis, spring-data etc.

因为它只是一个规范,您需要一个工具来实现它。该工具可以是Hibernate、TopLink、iBatis、spring-data等。

You don't necessarily require JPA if you are using Hibernate in your Data Layer. But if you use JPA specification for Hibernate, then it will make switching to other ORM tools like iBatis, TopLink easy in future, because the specification is common for others as well.

如果在数据层中使用Hibernate,则不一定需要JPA。但是,如果您为Hibernate使用JPA规范,那么它将使切换到其他ORM工具(如iBatis、TopLink)变得更加容易,因为该规范对其他人也很常见。

*(if you remember, you do import javax.persistence.*; when you use annotations for OR mapping (like @Id, @Column, @GeneratedValue etc.) in Hibernate, that's where you are using JPA under Hibernate, you can use JPA's @Query & other features as well)

*(如果您记得的话,您确实导入了javax.persistence.*;当您在Hibernate中使用注释或映射(比如@Id、@Column、@GeneratedValue等)时,您就可以在Hibernate中使用JPA,您也可以使用JPA的@Query和其他特性)

#16


2  

JPA is a Java API specification which describes the management of relational data in applications using Java Platform. where as Hibernate is a ORM (Object Relational Mapping) library which follows JPA specification.

JPA是一个Java API规范,它描述了使用Java平台的应用程序中关系数据的管理。其中Hibernate是遵循JPA规范的ORM(对象关系映射)库。

You can think JPA as a set of Rules which is implemented by Hibernate.

您可以将JPA视为由Hibernate实现的一组规则。

#17


2  

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是JSR,即实现对象关系映射的Java规范要求,它的实现没有特定的代码。它定义了访问、持久化和管理Java对象和关系数据库之间的数据的一组规则。Hibernate是使用te指南实现JPA的方法之一。Hibernate是一个高性能的对象/关系持久性和查询服务,它是在开源的GNU通用公共许可证(LGPL)下授权的,其好处是您可以将Hibernate的JPA实现替换为JPA规范的另一个实现。当您使用直接Hibernate时,您将锁定到实现中,因为其他ORM可能使用不同的方法/配置和注释,因此您不能仅仅切换到另一个ORM。

#18


1  

JPA is just a specification which needs concrete implementation. The default implementation provided by oracle is "Eclipselink" now. Toplink is donated by Oracle to Eclipse foundation to merge with eclipselink.

JPA只是一个需要具体实现的规范。oracle提供的默认实现是“Eclipselink”。Toplink由Oracle捐赠给Eclipse foundation以与eclipselink合并。

Using Eclipselink, one can be sure that the code is portable to any implementation if need arises. Hibernate is also a full JPA implementation + MORE. Hibernate is super set of JPA with some extra Hibernate specific functionality. So application developed in Hibernate may not be compatible when switched to other implementation. Still hibernate is choice of majority of developers as JPA implementation and widely used.

使用Eclipselink,您可以确保在需要时代码可以移植到任何实现。Hibernate也是一个完整的JPA实现+更多。Hibernate是JPA的超级集合,带有一些特定于Hibernate的功能。因此,在Hibernate中开发的应用程序在切换到其他实现时可能不兼容。不过,大多数开发人员选择hibernate作为JPA实现并广泛使用。

Another JPA implementation is OpenJPA, which is an extension of Kodo implementation.

另一个JPA实现是OpenJPA,它是Kodo实现的扩展。

JPA vs Hibernate

JPA vs冬眠

#19


1  

I try to explain in very easy words.

Suppose you need a car as we all know their are several A class manufacturer like MERCEDES, BMW , AUDI etc.

假设你需要一辆车,因为我们都知道他们有好几个一流的制造商,像奔驰,宝马,奥迪等等。

Now in above statement CAR(is a specification) as every car have common features like thing with 4 wheels and can be driven on road is car...so its like JPA. And MERCEDES, BMW , AUDI etc are just using common car feature and adding functionality according to their customer base so they are implementing the car specification like hibernate , iBATIS etc.

现在在上面的声明汽车(是一种规格),因为每辆车都有共同的特点,比如有4个*,可以在路上行驶的是汽车……所以它像JPA。奔驰、宝马、奥迪等都只是使用普通的汽车功能,并根据客户的需求增加功能,所以他们正在实现hibernate、iBATIS等汽车规格。

So by this common features goes to jpa and hibernate is just an implementation according to their jboss need.

因此,通过这些常见的特性,hibernate只是根据jboss的需要实现的。

1 more thing

JPA includes some basic properties so in future if you want to change hibernate to any other implementation you can easily switch without much headache and for those basic properties includes JPA annotations which can work for any implementation technology, JPQL queries.

JPA包含一些基本的属性,因此将来如果您想要将hibernate更改为任何其他实现,您可以轻松切换,而对于这些基本属性,JPA注释可以用于任何实现技术,JPQL查询。

So mainly we implement hibernate with JPA type technology just for in case we want to switch our implementation according to client need plus you will write less code as some common features are involved in JPA. If someone still not clear then you can comment as i m new on stack overflow.

因此,我们主要使用JPA类型技术实现hibernate,如果我们想要根据客户需求来切换我们的实现,那么您将编写更少的代码,因为一些常见的特性涉及到JPA。如果有人仍然不清楚,那么你可以评论我是新的关于栈溢出。

Thank you

#20


0  

JPA is just a specification while Hibernate is one of the JPA provider i.e hibernate is implementing various things mentioned in JPA contract.

JPA只是一个规范,而Hibernate是JPA提供者之一。e hibernate实现了JPA契约中提到的各种功能。

#21


0  

JPA or Java Persistence API is a standard specification for ORM implementations whereas Hibernate is the actual ORM implementation or framework.

JPA或Java持久性API是ORM实现的标准规范,而Hibernate是实际的ORM实现或框架。

#22


-1  

JPA is Java Persistence API. Which Specifies only the specifications for APIs. Means that the set of rules and guidelines for creating the APIs. If says another context, It is set of standards which provides the wrapper for creating those APIs , can be use for accessing entity object from database. JPA is provided by oracle.When we are going to do database access , we definitely needs its implementation. Means JPA specifies only guidelines for implementing APIs. Hibernate is a JPA provider/Vendor who responsible for implementing that APIs. Like Hibernate TopLink and Open JPA is some of examples of JPA API providers. So we uses JPA specified standard APIs through hibernate.

JPA是Java持久性API。它只指定api的规范。意味着创建api的规则和指导原则的集合。如果说另一个上下文,它是一组标准,为创建这些api提供包装器,可以用于从数据库访问实体对象。JPA由oracle提供。当我们要进行数据库访问时,我们肯定需要它的实现。意味着JPA只指定实现api的指导方针。Hibernate是一个JPA提供者/供应商,负责实现那些api。与Hibernate TopLink和Open JPA一样,JPA API提供程序也有一些例子。因此,我们通过hibernate使用JPA指定的标准api。

#23


-2  

Figuratively speaking JPA is just interface, Hibernate/TopLink - class (i.e. interface implementation).

打个比方,JPA只是接口、Hibernate/TopLink - class(即接口实现)。

You must have interface implementation to use interface. But you can use class through interface, i.e. Use Hibernate through JPA API or you can use implementation directly, i.e. use Hibernate directly, not through pure JPA API.

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

Good book about JPA is "High-Performance Java Persistence" of Vlad Mihalcea.

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