简体   繁体   English

如果JPA实际上只是一个规范,那我们该怎么办?

[英]If JPA is really only a specification, then how can we do?

In the question below EVERYBODY 在以下每个人的问题中

What's the difference between JPA and Hibernate? JPA和Hibernate有什么区别?

told that JPA is specification.It is something abstract without Eclipselink or Hibernate 告诉我们JPA是规范,这是没有Eclipselink或Hibernate的抽象

Is JPA javax.persistence.sth right? JPA javax.persistence.sth对吗?

Moreover we can use concrete things like 此外,我们可以使用诸如

javax.persistence.EntityManager.persiste javax.persistence.EntityManager.delete/remove javax.persistence.EntityManager.persiste javax.persistence.EntityManager.delete / remove

EDIT 编辑

Does eclipselink and hibernate put their own code into these packages, these classes??? eclipselink和hibernate是否将自己的代码放入这些包,这些类中???

JPA is a specification, and a number of implementors provide implementations that follow the specification. JPA是一个规范,许多实现者提供遵循该规范的实现。

So, if you use JPA as it is meant to be used, you can then choose from one or more of the implementors and it should "plug-and-play" work. 因此,如果按原样使用JPA,则可以从一个或多个实现者中进行选择,并且它应该“即插即用”。 In other words, you shouldn't have to change your code, because the implementation will do what the specification promises. 换句话说,您不必更改代码,因为实现将执行规范所承诺的工作。

--- As for the difference between JPA and Hibernate --- ---关于JPA和Hibernate之间的区别---

JPA is a specification, but Hibernate is an implementation. JPA是一个规范,但是Hibernate是一个实现。 If you write against JPA you can change between JPA compatible implementations with some ease; 如果您针对JPA编写代码,则可以轻松地在JPA兼容的实现之间进行更改; but, if you write against Hibernate, to change you effectively need to rewrite your database access code. 但是,如果您针对Hibernate进行编写,则要进行更改,实际上需要重写数据库访问代码。

Note that Hibernate also provides some JPA compatibility, if you take care to use only the JPA compatible part of Hibernate, you effectively are writing against JPA with Hibernate providing the implementation. 请注意,Hibernate还提供了一些JPA兼容性,如果您只使用Hibernate的JPA兼容部分,则您实际上是使用Hibernate提供的实现针对JPA编写的。

There is a receipe for doing JPA development that works quite well at preventing non-JPA (implementation specific) code from being written. 有一个进行JPA开发的秘诀,可以很好地防止编写非JPA(特定于实现)的代码。

  1. Find the JPA jar for the version of JPA you are targeting. 找到您要定位的JPA版本的JPA jar。
  2. Add that jar to the compile class path, and the run time classpath. 将该jar添加到编译类路径和运行时类路径。
  3. Find the JPA provider you wish to use (Hibernate, etc). 查找您要使用的JPA提供程序(休眠等)。
  4. Add that / those jars to the run time classpath only. 将该/那些罐子仅添加到运行时类路径。

JPA is Java Persistence API released as a JSR (Java Specification Requests) by JCP (Java Community Process). JPA是Java持久性API,由JCP(Java社区流程)作为JSR(Java规范请求)发布。

It is kind of specification; 这是一种规范; in other words like interface, no implementation includes. 换句话说,例如接口,不包含任何实现。

Every vendor (implementors) who interested this spec needs to implement as it says in specification document. 每个对此规范感兴趣的供应商(实施者)都需要按照规范文档中的说明进行实施。

Here is example JPA 2.0 spec 这是示例JPA 2.0规范

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

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