The simplest solution would be to create the data source then set it as the default data source. Then you don't even need to set the data source in your persistence.xml
.
For example the following CLI commands will create the data source and set the default data source (java:comp/DefaultDataSource
).
embed-server
# Configure the driver
/subsystem=datasources/jdbc-driver=org.postgresql:add(driver-name=org.postgresql, driver-module-name=org.postgresql, driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)
# Configure the data source
/subsystem=datasources/data-source=postgresql:add(driver-name=org.postgresql, jndi-name="java:/jdbc/PostgresDS", enabled=true, connection-url="jdbc:postgresql://localhost/testdb", user-name=user, password="password")
# Change the default data source name java:comp/DefaultDataSource
/subsystem=ee/service=default-bindings:write-attribute(name=datasource, value=java:/jdbc/PostgresDS)
stop-embedded-server
Then in the persistence.xml
just remove the <jta-data-source>
tag.