Is there a way to initialize the EntityManager without a persistence unit defined? Can you give all the required properties to create an entity manager? I need to create the EntityManager from the user’s specified values at runtime. Updating the persistence.xml and recompiling is not an option.
Any idea on how to do this is more than welcomed!
You should define at least one persistence unit in the
persistence.xmldeployment descriptor.persistence.xmlfile:So if your target Application Server supports JTA (JBoss, Websphere, GlassFish), your
persistence.xmllooks like:If your target Application Server does not support JTA (Tomcat), your
persistence.xmllooks like:If your data source is not bound to a global JNDI (for instance, outside a Java EE container), so you would usually define JPA provider, driver, url, user and password properties. But property name depends on the JPA provider. So, for Hibernate as JPA provider, your
persistence.xmlfile will looks like:Transaction Type Attribute
So use this: