什么是JPA提供商? [英] What is a JPA Provider?

查看:136
本文介绍了什么是JPA提供商?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JPA的新手。根据我的理解,JPA本身不能做持久性。它需要JPA Provider来将数据保存到数据库中。

I am new to JPA. As per my understanding JPA itself cannot do persistence. It will need JPA Provider for persisting data into database.

JPA Provider:它是包含JPA flavor(javax.persistence)的供应商产品。例如Eclipselink,Toplink,Hibernate等。
http://www.tutorialspoint。 com / jpa / jpa_orm_components.htm

JPA Provider : It is the vendor product that contains the JPA flavor (javax.persistence). For example Eclipselink, Toplink, Hibernate, etc. http://www.tutorialspoint.com/jpa/jpa_orm_components.htm

因此,任何想要使用JPA进行持久化的应用程序都必须使用像Eclipselink,Toplink,Hibernate这样的提供程序,等等。这是正确的吗?

So any application which wants to use JPA for persistence it will have to use a Provider like Eclipselink, Toplink, Hibernate, etc. also. Is this correct?

推荐答案

为了提供进一步的解释,JPA是在JCP框架中指定的API作为答案请求(例如, JSR 338 for JPA 2.1)。

To provide further explanations, JPA is an API specified in the frame of the JCP as an answer to a request (e.g JSR 338 for JPA 2.1).

存在该规范的几种实现,主要是:

Several implementations of that specification exist, the main are:

  • EclipseLink
  • Hibernate
  • OpenJPA
  • DataNucleus

在Java平台的框架中,当实现标准API时,这是通过名为 SPI (用于服务提供者接口)。实现的每个供应商必须提供特定组件,该组件是单个接口,作为实现类的起点。 Java教程包括声音API的示例。必须在名称​​ META-INF / services / {{MyFullInterfaceName}} 之后的ClassLoader文件中提及实现类。

In the frame of the Java platform, when a standard API is implemented, this is specified via a system called SPI (for Service Provider Interfaces). Each "vendor" of an implementation has to provide a specific component which is a single interface as a starting point for the implementing classes. The Java tutorial includes an example for the sound API. An implementing class has to be mentioned in a file available to the ClassLoader after the name META-INF/services/{{MyFullInterfaceName}}.

对于JPA API,此起点是 PersistenceProvider interface(注意包名称中的spi部分)。每个实现都包含实现类的声明,例如在 eclipselink.jar 中,您可以找到文件 META-INF / services / javax.persistence.spi.PersistenceProvider (以完整接口名称命名,其中只包含提供者实现类的全名,在EclipseLink的情况下:

For the JPA API, this starting point is the PersistenceProvider interface (note the spi section in the package name). Each implementation includes the declaration of the implementing class, for exemple in the eclipselink.jar you can find a file META-INF/services/javax.persistence.spi.PersistenceProvider (named after the full interface name) which contains only the full name of the provider implementation class, in the case of EclipseLink:

org.eclipse.persistence.jpa.PersistenceProvider

大部分时间API的应用程序客户端不需要关心该声明,因为它包含在实现JAR中。应用程序必须使用这种文件的唯一情况是必须使用多个实现时,例如使用EclipseLink和Hibernate:

Most of time the application client of the API does not have to care about that declaration because it is included in the implementation JAR. The only case in which an application has to use that kind of file is when multiple implementations have to be used, for example with EclipseLink and Hibernate:

org.eclipse.persistence.jpa.PersistenceProvider
org.hibernate.ejb.HibernatePersistence

您可以找到persistence.xml文件中指定的实现类(< provider />标记)。

You find the implementing class also specified in the persistence.xml file (<provider/> tag).

有时,JPA提供程序表达式用于请参阅供应商(EclipseLink,Hibernate等),而不是软件组件。根据具体情况,两者都可视为有效。

Sometime, the JPA provider expression is used to refer to the "vendor" (EclipseLink, Hibernate, etc.) and not to the software component. Both can be considered as valid, depending on the context.

这篇关于什么是JPA提供商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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