是否可以使用 hbm xml Hibernate 配置以符合 JPA 2.0 的方式构建 EntityManagerFactory 和 EntityManager?文档似乎表明这是不可能的:
"The previous tutorials used the Hibernate-specific hibernate.cfg.xml configuration file. JPA, however, defines a different bootstrap process that uses its own configuration file named persistence.xml." —Chapter 4
我的 hbm xml 配置有数千行长并且有效;我宁愿不必手动重写为 orm.xml 和 persistence.xml。我也没有数据模型的写入权限来添加 Hibernate 或 JPA 注释。出于我的目的,我只需要 JPA API,而不需要 JPA 配置。
有什么办法可以做到这一点吗?
最佳答案
是的,这是可能的。可以通过在 persistence.xml 中设置以下属性来使用现有映射:
<property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"/>
值是 hibernate 特定配置的路径。也可以使用 JPA 映射部分覆盖 hibernate 样式映射。可以从文档中找到其他说明:http://docs.jboss.org/hibernate/core/4.0/hem/en-US/html_single#d0e708
关于Hibernate:在不重写映射的情况下从核心 API 切换到 JPA API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11305204/