Java JPA vs ORM vs Hibernate?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27462185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 04:24:35  来源:igfitidea点击:

JPA vs ORM vs Hibernate?

javahibernatejpaorm

提问by M Sach

I have read about them through various resources. Importants ones are :-

我已通过各种资源阅读了有关它们的信息。重要的是:-

  1. Wikipedia article about each of them
  2. What's the difference between JPA and Hibernate?
  1. 维基百科关于他们每个人的文章
  2. JPA 和 Hibernate 有什么区别?

Here is my understanding about whats the difference b/w them. I am not sure if i am right about JPA vs ORM

这是我对黑白有什么区别的理解。我不确定我对 JPA 与 ORM 的看法是否正确

  1. ORM:Object Relational Mapping is concept/process of converting the data from Object oriented language to relational DB and vice versa For example in java its done with the help of reflection and jdbc.

  2. Hibernate:Its the implementation of above concept.

  3. JPA:Its the one step above ORM. Its high level API and specification so that different ORM tools can implement so that it provides the flexibility to developer to change the implementation from one ORM to another (for example if application uses the JPA api and implementaion is hibernate. In future it can switch to IBatis if required. But on the other if application directly lock the implementation with Hibernate without JPA platform, switiching is going to be herculean task)

  1. ORM:对象关系映射是将数据从面向对象语言转换为关系数据库的概念/过程,反之亦然。例如,在 java 中,它是在反射和 jdbc 的帮助下完成的。

  2. Hibernate:它是上述概念的实现。

  3. JPA:它比 ORM 高出一步。它的高级 API 和规范使不同的 ORM 工具可以实现,从而为开发人员提供了将实现从一种 ORM 更改为另一种的灵活性(例如,如果应用程序使用 JPA api 并且实现是休眠的。将来它可以切换到IBatis 如果需要。但另一方面,如果应用程序在没有 JPA 平台的情况下直接使用 Hibernate 锁定实现,那么切换将是一项艰巨的任务)

There can be ORM implementation with/without JPA specification.For example as per this linkunder hibernate section only Hibernate versions 3.2 and later provide an implementation for the Java Persistence API

可以有/没有 JPA 规范的 ORM 实现。例如,根据休眠部分下的此链接,只有 Hibernate 3.2 及更高版本提供 Java Persistence API 的实现

回答by Kevin Hooke

  1. ORM is the approach of taking object-oriented data and mapping to a relational data store (e.g. an RDBMS)

  2. Hibernate is an implementation of JPA and uses ORM technique.

  3. JPA is the EE standard specification for ORM in Java EE. Hibernate is also an implementation of this specification, in that you can use the standard JPA APIs and configure your application to use Hibernate as the provider of the spec under the covers.

  1. ORM 是一种将面向对象的数据映射到关系数据存储(例如 RDBMS)的方法

  2. Hibernate 是 JPA 的一个实现并使用 ORM 技术。

  3. JPA 是 Java EE 中 ORM 的 EE 标准规范。Hibernate 也是该规范的一个实现,因为您可以使用标准的 JPA API 并将您的应用程序配置为使用 Hibernate 作为该规范的提供者。

The features that Hibernate provides are also a superset of the ORM features specified in the JPA spec. Meaning, that while it provides an implementation of the JPA API, it also provides more features beyond what JPA specifies.

Hibernate 提供的功能也是 JPA 规范中指定的 ORM 功能的超集。这意味着,虽然它提供了 JPA API 的实现,但它还提供了超出 JPA 指定的更多功能。

回答by Miguel ángel

The only mistake you seemed to make in your understanding is

你似乎在理解上犯的唯一错误是

Its the one step above ORM

它是ORM之上的一步

One quick note, The libraries starting with javax.persistence are associated with JPA. You should prefer these over Hibernate Libraries whenever possible. Because these are Portable. However, you will get some extra features in Hibernate, and in those precise cases, please feel free to use Hibernate.

一个快速说明,以 javax.persistence 开头的库与 JPA 相关联。只要有可能,您应该更喜欢这些而不是 Hibernate Libraries。因为这些是便携式的。但是,您将在 Hibernate 中获得一些额外的功能,在这些特定情况下,请随意使用 Hibernate。