KunLun
KunLun

Reputation: 3227

Configure hibernate.connection.provider_class C3P0

I'm using Hibernate 5.4.3.Final and want to configure provider_class in hibernate.cfg.xml:

<property name="hibernate.connection.provider_class">
    <!-- path to C3P0ConnectionProvider class -->
</property>

I had tried with org.hibernate.connection.C3P0ConnectionProvider but Intellij can't find this class.

I also have hibernate-c3p0 in dependencies:

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

Can you help me with value path to C3P0ConnectionProvider?

Upvotes: 2

Views: 2910

Answers (2)

user3073180
user3073180

Reputation: 65

Just to add here: The reason it could not find the provider_class was because the path to it was incorrect. It should be- org.hibernate.c3p0.internal.C3P0ConnectionProvider. You will be able to see the path if you download the jar and unjar it.

Upvotes: 0

Anish B.
Anish B.

Reputation: 16559

Add these dependencies to 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>

Configure hibernate.cfg.xml to this :

<!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>

Upvotes: 4

Related Questions