Hibernate 无法识别来自 persistence.xml 的 DBCP 连接池配置
Hibernate does not recognize DBCP connection pool configurations from persistence.xml
我想在 SE 环境中使用来自 Apache commons 的 DBCP2 连接池:(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>
但是 Hibernate 不承认这一点,仍然使用它内置的连接池:
WARN org.hibernate.orm.connections.pooling - HHH10001002: Using Hibernate built-in connection pool (not for production use!)
喜欢coladict mentioned in his ,
Hibernate does not support automatic configuration for Apache commons dbcp2.
支持
C3P0, Proxool and Hikari. They are checked in that order.
我想在 SE 环境中使用来自 Apache commons 的 DBCP2 连接池:(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>
但是 Hibernate 不承认这一点,仍然使用它内置的连接池:
WARN org.hibernate.orm.connections.pooling - HHH10001002: Using Hibernate built-in connection pool (not for production use!)
喜欢coladict mentioned in his
Hibernate does not support automatic configuration for Apache commons dbcp2.
支持
C3P0, Proxool and Hikari. They are checked in that order.