The JPA spec. Defines the JPA annotation in the package javax.persistence
. Hibernate isn't 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 th ESE annotation inside the packageorg.hibernate.annotations
If There is no Hibernate specified features added for that JPA annotation (eg @OneToMany
@ManyToOne
and), Hibernate won't make that annotation in their package and you had to use org.hibernate.annotations
these annotation from javax.persistence
according to the JPA specification.
Normally, people would use JPA annotations until they come across a situation the requires to use hibernate features.
In one word:
If you want to use hibernate with annotation, you must use some annotations in the package javax.persistence
.
Extends:1,JPA (Java Persistence API) is the Java Persistence specification proposed by Sun. It provides Java developers with an object/relational mapping tool to manage relational data in Java applications. , and Hibernate is one of its implementations. In addition to hibernate, there are Eclipselink (formerly TopLink), OPENJPA, etc. to choose from, so one advantage of using JPA is that you can replace the implementation without having to change too much code.
2,hibernate as a JPA implementation, JPA annotations are already at the heart of Hibernate, and Hibernate provides only a few additions, not two sets of annotations. Hibernate support for JPA is sufficient, and JPA is recommended for use with Hibernate annotations.
About Annotations-hebernate and JPA (Java Persistence API)