3.5.2.2. Setting the DataSource at runtime
As mentioned above, the JTA and Non-JTA DataSources may be passed in as configuration properties at EntityManagerFactory creation.
Either the JPA standard properties ( jakarta.persistence.jtaDataSource, java.persistence.nonJtaDataSource) or their OpenJPA specific equivalents (openjpa.ConnectionFactoryName, openjpa.ConnectionFactory2Name) may be used.
One use case for this function is to store production connection information in configuration files but override the value when testing.
Example 51. Setting DataSource at Runtime
Map<Object,Object> props = new HashMap<Object,Object>();
props.put("jakarta.persistence.jtaDataSource", "jdbc/myDataSource");
props.put("jakarta.persistence.nonJtaDataSource", "jdbc/myNonJTADataSource");
emf = Persistence.createEntityManagerFactory("example", props);