小编典典

JPA实体和hibernate实体之间的区别

hibernate

当我使用@Entity注释类并尝试解析依赖项时,我可以在两个不同的包javax.persistence.Entity和org.hibernate.annotations.Entity中选择包。

javax包是JPA的实体注释,但是为什么会有hibernate的实体注释,它与JPA的注释有区别?仅仅是允许定义更多属性的扩展吗?


阅读 251

收藏
2020-06-20

共1个答案

小编典典

org.hibernate.annotations.Entity具有一些javax.persistence.Entity尚未标准化的额外属性。仅当AnnotationConfiguration直接使用hibernate
或JPA提供程序为hibernate时,这些附加功能才有效。

常见问题解答编辑:
新建链接特定问题
编辑: 新建链接答案

我使用@ org.hibernate.annotations.Entity并获得未知实体异常

始终导入@ javax.persistence.Entity

@ org.hibernate.annotations.Entity完成@ javax.persistence.Entity,但不能替代

例如,有一个名为的属性optimisticLock,该属性告诉hibernate 在更新时是使用标准 版本列
还是比较所有列。此行为不在JPA规范中,因此为了对其进行配置,必须使用在其自己的注释中找到的特定于hibernate的扩展。

像这样:

@Entity
@org.hibernate.annotations.Entity(optimisticLock=OptimisticLockType.ALL)
public class MyEntity implements Serializable {
...
}
2020-06-20