【问题标题】:Hibernate: switch from core API to JPA API without rewriting mappingHibernate:在不重写映射的情况下从核心 API 切换到 JPA API
【发布时间】:2012-07-03 05:53:27
【问题描述】:

是否可以使用 hbm xml Hibernate 配置以符合 JPA 2.0 的方式构建 EntityManagerFactory 和 EntityManager?文档似乎表明这是不可能的:

“之前的教程使用了特定于 Hibernate 的 hibernate.cfg.xml 配置文件。然而,JPA 定义了一个不同的引导过程,它使用自己的名为 persistence.xml 的配置文件。” ——Chapter 4

我的 hbm xml 配置长达数千行并且可以正常工作;我宁愿不必手动重写为 orm.xml 和 persistence.xml。我也没有数据模型的写入权限来添加 Hibernate 或 JPA 注释。出于我的目的,我只需要 JPA API,而不需要 JPA 配置。

有没有办法做到这一点?

【问题讨论】:

    标签: hibernate jpa-2.0


    【解决方案1】:

    是的,这是可能的。可以通过在 persistence.xml 中设置以下属性来使用现有映射:

    <property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"/>
    

    值是休眠特定配置的路径。也可以使用 JPA 映射部分覆盖休眠样式映射。可以从文档中找到其他说明:http://docs.jboss.org/hibernate/core/4.0/hem/en-US/html_single#d0e708

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-16
      • 2016-01-15
      • 2011-06-14
      • 2018-06-18
      • 2018-04-01
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多