Persistence.createEntityManagerFactory () in Java EE ignores JTA source

I have a perfectly working application client deployed on GlassFish v2 server inside the ear with some EJBs, entities, etc. I am using eclipselink.

I currently have in my persistence.xml:

<persistence-unit name="mysource">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/mysource</jta-data-source>
    <class>entities.one</class>
    <class>entities.two</class>
    ...
    <properties>
      <property name="eclipselink.target-server" value="SunAS9"/>
      <property name="eclipselink.logging.level" value="FINE"/>
    </properties>
</persistence-unit>

And this works great when I insert EntityManagerin EJB:

@PersistenceContext(unitName="mysource")
private EntityManager em;

Now I have a requirement to dynamically switch save / database units. I suppose I can get EntityManagerprogrammatically:

em = Persistence.createEntityManagerFactory("mysource").createEntityManager();

but I get the following error:

Unable to acquire a connection from driver [null], user [null] and URL [null]

Even "overriding" javax.persistence.jtaDataSource "to" jdbc / mysource "in Mapand the call createEntityManagerFactory("mysource", map)does not matter.

What am I missing?

+3
1

, , , , , JTA ( , RESOURCE_LOCAL), , .

unitName RESOURCE_LOCAL.

+1

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


All Articles