Hibernate:在不重写映射的情况下从核心 API 切换到 JPA API

标签 hibernate jpa-2.0

是否可以使用 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/

相关文章:

java - HQL 并检查对象是否为空或对象字段是否具有特定值

java - Spring全局事务在获取元素后提交

java - 提交表单时 Struts 2 Hibernate 空指针异常

java - 如何将 Hibernate 实体拦截器与 JPA 事务管理器一起使用?

hibernate - 尝试编写JPA 2.1左外部联接时获取 "with clause can only reference columns in the driving table"

java - 这个 JPA 映射到底是如何工作的?

hibernate - JPA 2.0 实现比较 : Hibernate 3. 5 vs EclipseLink 2 vs OpenJPA 2

java - OpenJPA:级联删除抛出 PersistenceException

java - hibernate中的传递持久性顺序

jpa-2.0 - @Inject 和 @EJB 有什么区别