Hibernate: switch from core API to JPA API without rewriting mapping

佐手、 提交于 2019-12-05 02:17:55

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/11305204/hibernate-switch-from-core-api-to-jpa-api-without-rewriting-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!