Hibernate:从核心API切换到JPA API,而无需重写映射 [英] Hibernate: switch from core API to JPA API without rewriting mapping

查看:91
本文介绍了Hibernate:从核心API切换到JPA API,而无需重写映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


以前的教程使用Hibernate特定的hibernate.cfg.xml配置文件。然而,JPA定义了一个使用自己的名为persistence.xml的配置文件的不同引导进程。
- 第4章

我的hbm xml配置长达数千行,我宁愿不必手工重写为orm.xml和persistence.xml。我也没有对数据模型的写访问权限来添加Hibernate或JPA注释。为我的目的,我只需要JPA API,而不是JPA配置。



有没有办法做到这一点? 是的,有可能的。通过在persistence.xml中设置以下属性,可以使用现有的映射:

 < property name =hibernate.ejb.cfgfile值= hibernate.cfg.xml中/> 

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

Is it possible to use a hbm xml Hibernate configuration to build an EntityManagerFactory and EntityManager in a JPA 2.0-compliant manner? The documentation seems to indicate this isn't possible:

"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

My hbm xml configuration is many thousands of lines long and works; I'd rather not have to rewrite by hand as orm.xml and persistence.xml. I also don't have write access to the data model to add Hibernate or JPA annotations. For my purposes I only need the JPA API, not the JPA configuration.

Is there any way to accomplish this?

解决方案

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

这篇关于Hibernate:从核心API切换到JPA API,而无需重写映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆