The JPA spec. defines the JPA annotation in the javax.persistence
package. Hibernate not only implements JPA spec , but extends it to adds more features . So , hibernate creates their own annotations which just extend the JPA annotation with the Hibernate features , and put these annotation inside the package org.hibernate.annotations
If there are no Hibernate specified features added for that JPA annotation (eg @OneToMany
and @ManyToOne
) , Hibernate will not make that annotation in their org.hibernate.annotations
package and you have to use these annotation from javax.persistence
according to the JPA specification.
Normally ,people will use JPA annotations until they come across a situation that requires to use hibernate features.
In one word: if you want to use hibernate with annotation, you must use some annotations in the javax.persistence
package.
Extends:
1,JPA(Java Persistence API)是Sun官方提出的Java持久化规范。它为Java开发人员提供了一种对象/关系映射工具来管理Java应用中的关系数据。,而Hibernate是它的一种实现。除了Hibernate,还有EclipseLink(曾经的toplink),OpenJPA等可供选择,所以使用Jpa的一个好处是,可以更换实现而不必改动太多代码。
2,Hibernate作为JPA的一种实现,jpa的注解已经是hibernate的核心,hibernate只提供了一些补充,而不是两套注解。hibernate对jpa的支持够足量,在使用hibernate注解建议使用jpa。