I want to use DBCP2 connection pooling from Apache commons in an SE environment: (build.gradle)
compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.2.0'
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="MyPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.myapp.MyModel</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/my_db"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="javax.persistence.jdbc.password" value="mypassword"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.dbcp.initialSize" value="5"/>
<property name="hibernate.dbcp.maxTotal" value="20"/>
<property name="hibernate.dbcp.maxIdle" value="10"/>
<property name="hibernate.dbcp.minIdle" value="5"/>
<property name="hibernate.dbcp.maxWaitMillis" value="-1"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
But Hibernate does not recognize this and still uses its built-in connection pooling:
WARN org.hibernate.orm.connections.pooling - HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Like coladict mentioned in his comment,
Hibernate does not support automatic configuration for Apache commons dbcp2.
It supports
C3P0, Proxool and Hikari. They are checked in that order.