问题
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