`
weigang.gao
  • 浏览: 467462 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

org.hibernate.annotations.Entity和javax.persistence.Entity 区别?

 
阅读更多

在@Entity时很容易顺手导入@org.hibernate.annotations.Entity这个包,结果导致了异常。其实应该导入的是@javax.persistence.Entity 

 

Always import @javax.persistence.Entity 

@org.hibernate.annotations.Entity是@javax.persistence.Entity的一个补充,但不是后者的替代品 

 

如果import @org.hibernate.annotations.Entity的话,会报异常。 

 

如果想使用@org.hibernate.annotations.Entity所包含的特殊的功能的话,需要在import @javax.persistence.Entity的基础上增加注释,如下: 

 

@Entity

@org.hibernate.annotations.Entity(optimisticLock=OptimisticLockType.ALL)

public class MyEntity implements Serializable {

...

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics