Create Factory entity manager without persistence.xml

Is there a way to create an EntityManagerFactory without a duration unit ? Can you provide all the necessary properties to create a factory entity manager? I need to create an EntityManagerFactory from user-defined values ​​at runtime. Updating persistence.xml and recompiling is not an option.

I am currently using dynamic eclipse persistence , so I need to create an EntityManagerFactory without a specific save unit. I have groups of runtime objects that need to map one group of objects to different databases at runtime, and for this group of entities for continuous operation there is no record of the unit of measure for duration.

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

+2
source share
2 answers
0

DataNucleus:

import org.datanucleus.metadata.PersistenceUnitMetaData;
import org.datanucleus.api.jpa.JPAEntityManagerFactory;

PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null);
pumd.addClassName("org.datanucleus.test.A");
pumd.setExcludeUnlistedClasses();
pumd.addProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:nucleus");
pumd.addProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
pumd.addProperty("javax.persistence.jdbc.user", "sa");
pumd.addProperty("javax.persistence.jdbc.password", "");
pumd.addProperty("datanucleus.autoCreateSchema", "true");

EntityManagerFactory emf = new JPAEntityManagerFactory(pumd, null);

http://www.datanucleus.org/products/accessplatform_3_2/jpa/persistence_unit.html

-2

Source: https://habr.com/ru/post/1529437/


All Articles