【问题标题】:Hibernate does not recognize DBCP connection pool configurations from persistence.xmlHibernate 无法识别来自 persistence.xml 的 DBCP 连接池配置
【发布时间】:2018-06-27 07:55:26
【问题描述】:

我想在 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!)

【问题讨论】:

  • Hibernate 不支持 Apache commons dbcp2 的自动配置。你需要给 Hibernate 配置的连接池,而不是一个的配置参数。
  • 那么Hibernate“自动”支持哪些连接池呢?
  • C3P0、Proxool 和 Hikari。它们按该顺序进行检查。这个例子应该很有用boraji.com/hibernate-5-hikaricp-configuration-example
  • @coladict 有没有办法为 dbcp2 配置它?
  • @RashimCatalanDhaubanjar 您可以实现对它的支持并将它的补丁提交给 Hibernate 团队。除此之外,没有。

标签: hibernate jpa persistence.xml apache-commons-dbcp


【解决方案1】:

就像他的comment中提到的coladict

Hibernate 不支持 Apache commons dbcp2 的自动配置。

支持

C3P0、Proxool 和 Hikari。它们按该顺序进行检查。

【讨论】:

    猜你喜欢
    • 2015-01-22
    • 2012-07-06
    • 2019-03-03
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    • 2013-05-28
    相关资源
    最近更新 更多