简体   繁体   English

Javax.Persistence和Hibernate.Annotations之间的区别

[英]Difference between Javax.Persistence and Hibernate.Annotations

I was reading the hibernate tutorial on tutorialspoint , they say that in order to use annotations with Hibernate it is required to have the following dependencies: 我正在阅读关于tutorialspoint的hibernate教程,他们说为了在Hibernate中使用注释,需要具有以下依赖项:

hibernate-annotations.jar
hibernate-comons-annotations.jar 
ejb3-persistence.jar

I've fetched those dependencies with Maven, but then when they continue with their example, they import javax.persistence rather than org.hibernate.annotations to use the annotations such as @Entity @Table etc... 我已经使用Maven获取了这些依赖项,但是当他们继续他们的示例时,他们导入javax.persistence而不是org.hibernate.annotations来使用注释,例如@Entity @Table等...

What is the difference between javax.persistence and org.hibernate.annotations ? javax.persistenceorg.hibernate.annotations什么区别? and why do I feel like I downloaded hibernate's annotations and I'm not using them? 为什么我觉得我下载了hibernate的注释而我没有使用它们?

You use javax.persistence to keep implementation-agnostic (ie you can change to use a different JPA implementation later.) If you want to just go with Hibernate, you can use org.hibernate annotations. 您使用javax.persistence来保持与实现无关(即您可以在以后更改为使用不同的JPA实现。)如果您想使用Hibernate,可以使用org.hibernate注释。 But it's advisable to just import the javax classes rather. 但是建议只输入javax类。 Then Hibernate will provide the implementation, but can be replaced by just switching in a different dependency. 然后Hibernate将提供实现,但可以通过切换不同的依赖项来替换。

The javax.* packages are defined by JSRs (java specification requests). javax。*包由JSR(java规范请求)定义。 Like an interface, the javax packages defines contracts. 像接口一样,javax包定义了契约。 Providers, such as hibernate, supply the implementation. 提供者,如hibernate,提供实现。 By using the javax imports, you decouple yourself from a specific provider and retain the ability to switch to a different implementation in the future. 通过使用javax导入,您可以将自己与特定提供程序分离,并保留将来切换到其他实现的能力。

Here's a list of other JSRs beyond javax.persistence ( https://jcp.org/ja/jsr/all ). 以下是javax.persistence( https://jcp.org/ja/jsr/all )之外的其他JSR列表。 The javax.persistence (2.0) specification is defined by JSR-317 . javax.persistence(2.0)规范由JSR-317定义。

javax.persistence is Java EE standard which is standard implementation. javax.persistence是Java EE标准,是标准实现。 But org.hibernate.annotations hibernate specific implementation like wise there are other ORM framework implementation such as Toplink, Eclipselink etc. Tomorrow if you feel to switch the framework it becomes easier. org.hibernate.annotations hibernate特定的实现就像明智的还有其他ORM框架实现,如Toplink,Eclipselink等。明天,如果你觉得切换框架变得更容易。

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

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