【问题标题】:Difference between JPA Entity and Hibernate EntityJPA 实体和 Hibernate 实体的区别
【发布时间】:2010-10-31 15:05:34
【问题描述】:

当我使用 @Entity 注释一个类并尝试解决依赖关系时,我可以在 javax.persistence.Entity 和 org.hibernate.annotations.Entity 这两个不同的包之间选择包

javax包是JPA的entity-annotation,但是为什么会有hibernate entity-annotation,和JPA的annotation有什么区别呢?它只是允许定义更多属性的扩展吗?

【问题讨论】:

    标签: java hibernate jpa


    【解决方案1】:

    org.hibernate.annotations.Entity 有一些javax.persistence.Entity 没有标准化的额外属性。只有当直接使用 hibernate 的 AnnotationConfiguration 或者 hibernate 是 JPA 提供者时,额外的功能才会起作用。

    来自the FAQ编辑: 新链接the specific question: 罢工> 编辑: 新链接the answer

    我使用@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 {
    ...
    }
    

    【讨论】:

      【解决方案2】:

      在你的项目中使用@org.hibernate.annotations,如果你想使用JDBC模板或ibatis我们需要更改代码。如果我们使用 javax.persistence,则无需更改代码。这是 org.hibernate.annotations 和 javax 持久化的主要区别

      【讨论】:

        【解决方案3】:

        我不确定这些差异,但我确信如果您的类路径中有 Hibernate jar,那么您使用的是 Hibernate JPA。 Hibernate 提供了 JPA 的实现。即使您使用的是 javax.persistence 包,您也使用的是 Hibernate JPA。

        区别可能仅在于命名。它们可能在 Hibernate 包空间和 javax 包空间中提供相同的类。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-03-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-08-26
          • 2018-07-03
          • 2015-11-05
          • 2011-09-22
          相关资源
          最近更新 更多