配置hibernate.connection.provider_class C3P0

时间:2019-07-15 16:23:46

标签: java hibernate

我正在使用jQuery('#idOfNeededField, #idOfNeededField-2, #idOfNeededField-3').change(function(){ let allowedToPublish = true; if (jQuery('#idOfNeededField').text().length = 0) { allowedToPublish = false; } if (jQuery('#idOfNeededField-2').text().length = 0) { allowedToPublish = false; } if (jQuery('#idOfNeededField-3').text().length = 0) { allowedToPublish = false; } if (allowedToPublish) { jQuery('#idOfButton').enable(); } } ,并想在Hibernate 5.4.3.Final中配置provider_class

hibernate.cfg.xml

我尝试过使用<property name="hibernate.connection.provider_class"> <!-- path to C3P0ConnectionProvider class --> </property> ,但是Intellij找不到此类。

我也有org.hibernate.connection.C3P0ConnectionProvider依赖项:

hibernate-c3p0

您能为我提供<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-c3p0</artifactId> <version>5.4.3.Final</version> </dependency> 的价值之路吗?

2 个答案:

答案 0 :(得分:2)

将这些依赖项添加到 pom.xml

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.4.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>5.4.3.Final</version>
    </dependency>
   <dependency>
        <groupId>c3p0</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.1.2</version>
   </dependency>

为此配置hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/db?useSSL=false&amp;serverTimezone=UTC</property>
    <property name="connection.username">user</property>
    <property name="connection.password">password</property>
    <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
    <property name="show_sql">true</property>
    <!-- c3p0 connection pool -->
    <property name="hibernate.c3p0.min_size">1</property>
    <property name="hibernate.c3p0.max_size">100</property>
    <property name="hibernate.c3p0.timeout">200</property>
    <property name="hibernate.c3p0.max_statements">100</property>
    <property name="hibernate.c3p0.idle_test_period">5000</property>
</session-factory>
</hibernate-configuration>

答案 1 :(得分:0)

只需在此处添加:找不到provider_class的原因是因为它的路径不正确。它应该是org.hibernate.c3p0.internal.C3P0ConnectionProvider。如果下载jar并将其解压缩,您将能够看到路径。