title: Configure HikariCP + Hibernate + GuicePersist(JPA) at Runtime
body: <p>I have a java8 desktop app using GuicePersist, Hibernate, and HikariCP to communicate with a Postgres DB. I've had success getting my app to send/receive data to the DB using this META-INF/persistence.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"&gt;
      &lt;!-- A JPA Persistence Unit --&gt;
      &lt;persistence-unit name="myJPAunit" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
          &lt;class&gt;com.123fakestreet.bogus.tomb.impl.postgres.model.movies&lt;/class&gt;
          &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;
          &lt;properties&gt;
              &lt;!-- SQL stuff --&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect" /&gt;
              &lt;property name="hibernate.show_sql" value="false" /&gt;
              &lt;property name="hibernate.format_sql" value="true" /&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="validate" /&gt;
  
              &lt;!-- hikari CP --&gt;
              &lt;property name="hibernate.connection.provider_class" value="org.hibernate.hikaricp.internal.HikariCPConnectionProvider" /&gt;
              &lt;property name="hibernate.hikari.minimumIdle" value="20" /&gt;
              &lt;property name="hibernate.hikari.maximumPoolSize" value="100" /&gt;
              &lt;property name="hibernate.hikari.idleTimeout" value="30000" /&gt;
              &lt;property name="hibernate.hikari.dataSourceClassName" value="org.postgresql.ds.PGSimpleDataSource" /&gt;
              &lt;property name="hibernate.hikari.dataSource.url" value="jdbc:postgresql://192.168.100.75:5432/mpDb" /&gt;
              &lt;property name="hibernate.hikari.username" value="cowboy" /&gt;
              &lt;property name="hibernate.hikari.password" value="bebop" /&gt;
  
              &lt;!-- Disable the second-level cache  --&gt;
              &lt;property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/&gt;
  
              &lt;!-- Default is false for backwards compatibility.  Should be used on all new projects --&gt;
              &lt;property name="hibernate.id.new_generator_mappings" value="true"/&gt;
  
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>The tricky part is configuring my Guice JpaPersistModule at runtime.
  From what I can tell, I should be able to override properties in my META-INF/persistence.xml file by setting properties in a Map object, like this:</p>
  
  <pre><code>Map&lt;String, String&gt; properties = new HashMap&lt;&gt;();
      properties.put("myJPAunit.hibernate.hikari.dataSource.url", "jdbc:postgresql://192.168.100.75:5432/mpDb");
      properties.put("myJPAunit.hibernate.hikari.dataSource.user", "cowboy");
      properties.put("myJPAunit.hibernate.hikari.dataSource.password", "bebop");
  </code></pre>
  
  <p>then jpaModule.properties(properties), and then pass this all to GuicePersist.</p>
  
  <p>I've tried some different combinations of property names in the Map but so far I've had no luck. I've also looked at the pgsimpledatasource docs and the hikariCP docs regarding this topic, but still my datasource properties are not getting set. </p>
  
  <p>Can somebody help? Thanks a bunch.</p>