什么是JPA实现? [英] What is a JPA implementation?

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

问题描述

我正在开始使用JPA,对于JPA实现(EclipseLink,TopLink,Hibernate等)究竟是什么,我感到困惑。

I'm getting started with JPA, and I'm confused as to what exactly the JPA implementation(EclipseLink, TopLink, Hibernate, etc.) does.

我了解JPA的理论作用,但是各种实现的目的是什么?这些选择之间是否存在显着的差异,因为有DB连接器/驱动程序?对于初学者来说,哪个是最好的?

I understand the theoretical role of JPA, but what is the purpose of the various implementations? Are there significant differences between these choices, as there is with say, DB connectors/drivers? Which is the best one for a beginner?

我可能会和EclipseLink一起去,因为这是我读过的大部分文献。

I'll probably go with EclipseLink because that is what most of the literature I've read uses.

推荐答案

JPA只是一个需要实现使用的API(因此是Java Persistence API )。

JPA is just an API (hence Java Persistence API) that requires an implementation to use.

类比将使用JDBC。 JDBC是用于访问数据库的API,但您需要一个实现(驱动程序jar文件)才能连接到数据库。如果没有驱动程序,你不能对数据库做任何事情。

An analogy would be using JDBC. JDBC is an API for accessing databases, but you need an implementation (a driver jar file) to be able to connect to a database. On its own, without a driver, you cannot do anything with a database.

如JPA所述,您需要一个实现,一组

With JPA, as I said, you need an implementation, a set of classes that lie "below" JPA, and such an implementation will do what you want.

您的应用程序使用JPA API(这个措辞有点夸张,但我希望你得到想法),然后与基础实现进行通信。

Your application uses the JPA API (this wording is a bit cubersome, but I hope you get the idea), which then communicates with the underlying implementation.

常用的实现包括 Hibernate EclipseLink OpenJPA 等。

Popular implementations include Hibernate, EclipseLink, OpenJPA and others.

其中每一个都实现了JPA API,所以如果你只使用JPA,每个实现应该行为一样。

Every one of them implement the JPA API, so if you use only JPA, every implementation should act the same.

但是!这些实现提供的功能可能超出了标准的JPA API。

But! The functionality provided by these implementations might go beyond the standard JPA API.

如果要使用此特定功能,您将不得不使用不属于供应商的API

If you want to use this particular functionality, you will have to use vendor specific API that will not be compatible with others.

例如,即使JPA使用ID生成选项定义了 @Id 注释,当使用Hibernate,您还可以使用 @ org.hibernate.annotations.GenericGenerator 为Hibernate特定的生成策略。

For example, even though JPA defines the @Id annotation with ID generation options, when using Hibernate, you can use also @org.hibernate.annotations.GenericGenerator for Hibernate specific generation strategies.

使用此注释不会工作,除非您使用Hibernate作为底层实现。

Using this annotation will not work unless you're using Hibernate as the underlying implementation.

底线是:JPA是每个供应商实现的最不常用的分母,每个实施可能有一些更高级的功能,这些功能不是标准的。

The bottom line is: JPA is the "least common denominator" which every vendor implements, and every implementation might have some more advanced features that aren't standard.

如果您希望应用程序可移植,请仅使用JPA。如果您确定以后不会改变主意并切换实现,请使用JPA +供应商特定功能。

If you want your application to be portable, use only JPA. If you are sure you won't change your mind later on and switch implementations, use JPA + vendor specific features.

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

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