title: jpa custom connection pool
body: <p>I've successfully integrated hibernate in my web app. I was happy with my <code>persistence.xml</code> configuration</p>
  
  <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"&gt;
      &lt;persistence-unit name="PU"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" /&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="validate" /&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.SQLiteDialect" /&gt;
              &lt;property name="hibernate.show_sql" value="false" /&gt;
              &lt;property name="hibernate.format_sql" value="true" /&gt;
              &lt;property name="hibernate.connection.url" value="jdbc:sqlite:/tmp/database.db" /&gt;
              &lt;property name="hibernate.connection.driver_class" value="org.sqlite.JDBC" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Then I decided to use <strong>HikariCp</strong> connection pooler after reading <a href="https://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch01.html#d5e60" rel="nofollow">this</a></p>
  
  <blockquote>
    <p>The built-in connection pool is not intended for production environments</p>
  </blockquote>
  
  <p>With <a href="https://github.com/brettwooldridge/HikariCP/wiki/Hibernate4" rel="nofollow">this</a> example I managed to make it work partially with the new <code>persistence.xml</code></p>
  
  <pre><code>&lt;persistence-unit name="PU"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" /&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="validate" /&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.SQLiteDialect" /&gt;
              &lt;property name="hibernate.show_sql" value="true" /&gt;
              &lt;property name="hibernate.format_sql" value="true" /&gt;
              &lt;property name="hibernate.connection.provider_class" value="com.zaxxer.hikari.hibernate.HikariConnectionProvider" /&gt;
              &lt;property name="hibernate.hikari.minimumPoolSize" value="20" /&gt;
              &lt;!-- &lt;property name="hibernate.hikari.maximumPoolSize" value="100" /&gt; --&gt;
              &lt;property name="hibernate.hikari.idleTimeout" value="30000" /&gt;
              &lt;property name="hibernate.hikari.dataSourceClassName" value="org.sqlite.SQLiteDataSource" /&gt;
              &lt;property name="hibernate.hikari.dataSource.url" value="jdbc:sqlite:/tmp/database.db" /&gt;
              &lt;!-- &lt;property name="hibernate.hikari.dataSource.user" value="" /&gt;
              &lt;property name="hibernate.hikari.dataSource.password" value="" /&gt; --&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>But I get error if I try to set <em>minimumPoolSize</em>, <em>maximumPoolSize</em>, <em>user</em> and <em>password</em>. If comment them out everything works great.</p>
  
  <blockquote>
    <p>org.hibernate.HibernateException: java.lang.RuntimeException: java.beans.IntrospectionException: Method not found: setMinimumPoolSize</p>
  </blockquote>
  
  <p>How can I configure jpa to use hibernate with hikaricp pool? I prefer not to scatter hibernate-specific stuff in my code as I want to keep ORM layer abstract.
  I found a lot of confusing materials and got more questions than aswers. How are persistence.xml, hibernate.properties and hibernate.cfg.xml related to each other? What is JNDI and how to use it? And what is <a href="http://renren.io/questions/4878609/hikaricp-lots-of-database-connections" rel="nofollow">this</a> bean configuration?</p>