1

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!)
Archie
  • 962
  • 2
  • 9
  • 20
  • 1
    Hibernate does not support automatic configuration for Apache commons dbcp2. You need to give Hibernate the configured connection pool, not the configurations parameters for one. – coladict Jan 18 '18 at 12:07
  • Then what connection pools are "automatically" supported by Hibernate? – Archie Jan 18 '18 at 13:05
  • C3P0, Proxool and Hikari. They are checked in that order. This example should be useful https://www.boraji.com/hibernate-5-hikaricp-configuration-example – coladict Jan 18 '18 at 13:13
  • @coladict is there way to configure it for dbcp2 ? – Rashim Catalan Dhaubanjar Mar 06 '18 at 10:38
  • @RashimCatalanDhaubanjar you can implement support for it and propose it your patch to the Hibernate team. Other than that, no. – coladict Mar 06 '18 at 12:25

1 Answers1

0

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.

Archie
  • 962
  • 2
  • 9
  • 20