创建没有persistence.xml的实体管理器工厂 [英] Create Entity Manager Factory without persistence.xml

查看:156
本文介绍了创建没有persistence.xml的实体管理器工厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在没有定义持久性单元的情况下创建 EntityManagerFactory ?您可以提供创建实体管理器工厂的所有必需属性吗?我需要在运行时根据用户的指定值创建EntityManagerFactory.无法更新persistence.xml并重新编译.

Is there a way to create the EntityManagerFactory without a persistence unit defined? Can you give all the required properties to create an entity manager factory? I need to create the EntityManagerFactory from the user's specified values at runtime. Updating the persistence.xml and recompiling is not an option.

当前我正在使用 eclipselink动态持久性,因此我需要创建未定义持久性单元的EntityManagerFactory吗?我有几组运行时实体,它们需要在运行时将一组实体映射到不同的数据库,并且该实体组没有持久性单元条目.

Currently I am using eclipselink dynamic persistence so i need to create the EntityManagerFactory without a persistence unit defined ? I have groups of runtime entities that need to map single group of entities to different database in runtime and no persistence unit entry is available for this runtime group of entities .

任何有关如何执行此操作的想法都受到欢迎!

Any idea on how to do this is more than welcomed!

推荐答案

您最好的选择是最有可能直接访问PersistenceProvider并使用EJB容器API从PersistenceUnitInfo创建EntityManagerFactory.

Your best option is most likely to access the PersistenceProvider directly and use the EJB container API to create the EntityManagerFactory from a PersistenceUnitInfo.

PersistenceProvider.createContainerEntityManagerFactory()

PersistenceProvider.createContainerEntityManagerFactory()

看, 查看全文

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