i am using JPA in a JAR-Project and used the persistence.xml to setup my EntityManager.
But since the persistence.xml is inside the JAR after the build it is very complicated for the user to change the settings afterwards. So i'm looking for a solution where i can configure my connection over a propertyfile which is loaded at runtime.
I came across this solution on the web:
Map properties = new HashMap();
// Configure the internal EclipseLink connection pool
properties.put(JDBC_DRIVER, "oracle.jdbc.OracleDriver");
properties.put(JDBC_URL, "jdbc:oracle:thin:@localhost:1521:ORCL");
properties.put(JDBC_USER, "user-name");
properties.put(JDBC_PASSWORD, "password");
Persistence.createEntityManagerFactory("unit-name", properties);
Which is the solution i was looking for but i'm missing one thing here: In my persistence.xml i also declare a schema name over a mapping file:
persistence.xml:
<persistence version="2.0" ...>
<persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>...</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="..."/>
<property name="javax.persistence.jdbc.password" value="..."/>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="javax.persistence.jdbc.user" value="..."/>
</properties>
<mapping-file>META-INF/orm.xml</mapping-file>
</persistence-unit>
</persistence>
orm.xml:
<entity-mappings ...>
<persistence-unit-metadata>
<persistence-unit-defaults>
<schema>SCHEMA_NAME</schema>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>
So my question is basically: Is there a property i can use to set the schema at runtime, just like i do with the other properties?
Or is there even a better solution?
Thanks in advance!