当我使用@Entity注释类并尝试解决依赖关系时,我可以在两个不同的包javax.persistence.Entity和org.hibernate.annotations.Entity中选择包。
javax包是JPA的实体注释,但是为什么会有 hibernate 的实体注释,并且它与JPA的注释有区别?仅仅是允许定义更多属性的扩展吗?
最佳答案
org.hibernate.annotations.Entity
具有javax.persistence.Entity
尚未标准化的一些额外属性。仅当直接使用hibernate的AnnotationConfiguration
或hibernate是JPA提供程序时,这些附加功能才有效。
来自the FAQ:
编辑:新链接the specific question:
编辑:新链接the answer:
例如,有一个名为optimisticLock
的属性,它告诉hibernate在更新时是使用标准版本列还是比较所有列。此行为不在JPA规范中,因此要对其进行配置,必须使用在其自己的注释中找到的 hibernate 特定扩展。
像这样:
@Entity
@org.hibernate.annotations.Entity(optimisticLock=OptimisticLockType.ALL)
public class MyEntity implements Serializable {
...
}