user900721
user900721

Reputation: 1437

Hibernate annotation

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

Or is there no such rule?

Upvotes: 0

Views: 582

Answers (1)

Xavi López
Xavi López

Reputation: 27880

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

Upvotes: 7

Related Questions