简体   繁体   中英

Try to use C3P0 with Hibernate

I'm using JPA and have a persistence.xml with the following configuration:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd ">


    <persistence-unit name="odontonewPU">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="false" />
<!--            <property name="hibernate.hbm2ddl.auto" value="update" /> -->

            <!--   C3P0 configuration -->
            <property name="hibernate.connection.provider_class"
                value="org.hibernate.connection.C3P0ConnectionProvider" />

            <property name="hibernate.c3p0.max_size" value="100" />
            <property name="hibernate.c3p0.min_size" value="0" />
            <property name="hibernate.c3p0.acquire_increment" value="1" />
            <property name="hibernate.c3p0.idle_test_period" value="300" />
            <property name="hibernate.c3p0.max_statements" value="0" />
            <property name="hibernate.c3p0.timeout" value="100" />
        </properties>
    </persistence-unit>

</persistence>

The problem is that when i try to initialize my tomcat i got the following error:

691 [Thread-2] ERROR org.hibernate.connection.ConnectionProviderFactory - Could not instantiate connection provider
java.lang.ClassNotFoundException: org.hibernate.connection.C3P0ConnectionProvider

In my pom.xml (i use maven), i have the following dependency:

<dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>

That class is part of hibernate-c3p0 . You will need to add a dependency

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

or whichever version you need .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM