| Given this peristence.xml:
<persistence-unit name="optaweb-employee-rostering-persistence-unit" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
...
</persistence-unit>
This should work to overwrite the jta-data-source.
Map<String, String> properties = new HashMap<>();
properties.put("javax.persistence.transactionType", "RESOURCE_LOCAL");
properties.put("javax.persistence.jdbc.driver", "org.hsqldb.jdbcDriver");
properties.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:testdb");
properties.put("javax.persistence.jdbc.user", "sa");
properties.put("javax.persistence.jdbc.password", "");
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(
"optaweb-employee-rostering-persistence-unit", properties);
But instead, it crashes in JSE and unit tests because it tries to resolve "java:jboss/datasources/ExampleDS" from JNDI. The `javax.persistence.jdbc.url` should overwrite the jta-data-source entry. Even adding this doesn't fix it:
properties.put("javax.persistence.jtaDataSource", "");
In Eclipse Link it's apparently possible to overwrite the persistence.xml's <jta-data-source> element: https://stackoverflow.com/a/20819336/472109 In Hibernate, that approach doesn't work: https://stackoverflow.com/questions/51514433/jpa-reuse-persistence-xml-with-jta-data-source-in-jse-and-junit-by-overriding-t |