JPA vs ORM vs Hibernate
ORM
一个概念或是方法,把对象映射到关系型数据库。
JPA
java为ORM提供的API
Hibernate
JPA的一种实现,但也提供了其他功能。
JPA 和 Hibernate 的历史发展
Hibernate是最早产生的,JCP为了避免程序员代码和某个特定的ORM工具提供商(即Hibernate)的代码耦合,自己定义了API即JPA,提供商都来实现它,而Hibernate是他的实现之一,这样程序员只需要面对JPA编程,而不需要直接耦合Hibernate。但是Hibernate是JPA的超集,还有自己的功能,如果直接使用Hibernate自己定义的功能和标签,就直接依赖了Hibernate。
https://stackoverflow.com/a/21993987/5646921
Some things are too hard to understand without a historical perspective of the language and understanding of the 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)
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.
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.
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.
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.
Source: http://www.reddit.com/r/java/comments/16ovek/understanding_when_to_use_jpa_vs_hibernate/
Last updated
Was this helpful?