3

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

“以前的教程使用了特定于 Hibernate 的 hibernate.cfg.xml 配置文件。然而,JPA 定义了一个不同的引导过程,它使用自己的名为 persistence.xml 的配置文件。” —<a href="http://docs.jboss.org/hibernate/orm/4.1/quickstart/en-US/html/ch04.html" rel="nofollow">第 4 章

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

有没有办法做到这一点?

4

1 回答 1

7

Yes, it is possible. Existing mappings can be used by setting following property in persistence.xml:

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

Value is path to hibernate specific configuration. It is also possible to partially override hibernate style mappings with JPA mappings. Additional instructions can be found from documentation: http://docs.jboss.org/hibernate/core/4.0/hem/en-US/html_single#d0e708

于 2012-07-03T06:26:56.940 回答