Should we use @org.hibernate.annotations.Entity instead of @javax.persistence.Entity in Hibernate based ap开发者_高级运维plications?
Or is there no such rule?
@org.hibernate.annotations.Entity
complements @javax.persistence.Entity
.
See this tightly related question for details: Difference between JPA Entity and Hibernate Entity. As stated there, you shouldn't be using @org.hibernate.annotations.Entity
without @javax.persistence.Entity
. The Hibernate annotation will let you add some extra hibernate-specific features to the ones already defined in the standard JPA one.
The JPA annotation has the advantange of decoupling your code from the specific engine you're using, and the Hibernate annotation adds some extra features/attributes to the JPA standard annotation, like optimisticLock
. Only use @org.hibernate.annotations.Entity
if you need to use those attributes.
精彩评论