I'd recommend using Apache Maven to build, test, and deploy your application. Then you can just have src/main/webapp/META-INF/persistence.xml for your production persistence.xml, and src/test/resources/META-INF/persistence.xml as your test persistence.xml, and finally your src/test/java/MyArqTest.java you simply add a MetaInf("META-INF/persistence.xml") which will pick up the src/test/resources flavor because of the way Maven orders the classpath for each lifecycle phase.
On Tue, Nov 18, 2014 at 11:35 PM, hanas...@gmail.com <hanas...@gmail.com> wrote: > The question is: "how can the persistence.xml, which is generally included > in the same JAR as the JPA domain objects and DAO related code (ie: classes > that use entity manager) be configured to handle different database servers" > > There are two scenarios for this: > 1. testing - currently thinking that Arquillian will handle this by deleting > the persistence.xml and adding a testing specific one when the WAR is built > as part of the unit test - Other ideas / suggestions? > 2. run-time - for example the WAR is provided to several customers. One > customer runs Oracle and the other runs mysql. > > == > Generally planning to use either H2 or HSQLDB (maybe in memory) for JPA > based testing and another DB in production (MySQL, PostgreSQL, Oracle) > > Changing the datasource independently of the JAR or Code is quite easy in a > JEE container. However the persistence.xml is generally tailored to a > specific DB (see below) which creates the issue. > > ex: > <provider>... > <property> various... probably can add for multiple DB's > and those that do not apply will be ignored. > hibernate.dialect > org.hibernate.dialect