title: JPA: create EntityManagerFactory from properties
body: <p>i am using JPA in a JAR-Project and used the persistence.xml to setup my EntityManager. </p>
  
  <p>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.</p>
  
  <p>I came across this solution on the web:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>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:</p>
  
  <p>persistence.xml:</p>
  
  <pre><code>&lt;persistence version="2.0" ...&gt;
    &lt;persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
      &lt;class&gt;...&lt;/class&gt;
      &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;
      &lt;properties&gt;
        &lt;property name="javax.persistence.jdbc.url" value="..."/&gt;
        &lt;property name="javax.persistence.jdbc.password" value="..."/&gt;
        &lt;property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/&gt;
        &lt;property name="javax.persistence.jdbc.user" value="..."/&gt;
      &lt;/properties&gt;
      &lt;mapping-file&gt;META-INF/orm.xml&lt;/mapping-file&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>orm.xml:</p>
  
  <pre><code>&lt;entity-mappings ...&gt;
   &lt;persistence-unit-metadata&gt;
    &lt;persistence-unit-defaults&gt;
     &lt;schema&gt;SCHEMA_NAME&lt;/schema&gt;
    &lt;/persistence-unit-defaults&gt;
   &lt;/persistence-unit-metadata&gt;
  &lt;/entity-mappings&gt;
  </code></pre>
  
  <p>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?</p>
  
  <p>Or is there even a better solution?</p>
  
  <p>Thanks in advance!</p>