Hibernate annotation

前端 未结 1 437
盖世英雄少女心
盖世英雄少女心 2021-01-25 22:09

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

Or is there no such rule?

相关标签:
1条回答
  • 2021-01-25 22:52

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

    0 讨论(0)
提交回复
热议问题