0

Should we use @org.hibernate.annotations.Entity instead of @javax.persistence.Entity in Hibernate based applications?

Or is there no such rule?

James DW
  • 1,815
  • 16
  • 21
user900721
  • 1,417
  • 4
  • 17
  • 29
  • You might want to accept the answer to this and several previous questions you've asked, if they have solved your issues. – Xavi López Oct 20 '11 at 14:49

1 Answers1

7

@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.

Community
  • 1
  • 1
Xavi López
  • 27,550
  • 11
  • 97
  • 161