简体   繁体   中英

Trying to setup pooling with C3P0 Pooling in Hibernate with Spring WebFlow and MySQL

I am trying to setup pooling with C3P0 Pooling in Hibernate with Spring WebFlow and MySQL but I would like to have Hibernate managed the pools and not mysql so I setup my jdbc.properties file and my database.xml file and ran my project and checked the connections to the database and it looks like if I change the database.minPoolSize properties on the MySQL side it works but its not working if I change them on the Hibernate size. Can someone please review my files and let me know what you think:

jdbc.properties:

#
# database
#
database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://xxx
database.user=xxx
database.password=xxx
database.acquireIncrement=1
database.minPoolSize=5
database.maxPoolSize=25
database.maxIdleTime=1
#
# Hibernate
#
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=false
format_sql=false
hibernate.use_sql_comments=false;
#
# C3P0
#
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=25
hibernate.c3p0.timeout=600
hibernate.c3p0.max_statements=0
hibernate.c3p0.idle_test_period=300
hibernate.c3p0.acquire_increment=5

Here is my database.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context 
                            http://www.springframework.org/schema/context/spring-context-3.0.xsd
                            http://www.springframework.org/schema/tx
                            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                            http://www.springframework.org/schema/jdbc
                            http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">



    <context:property-placeholder location="classpath:jdbc.properties" />

    <context:component-scan base-package="org.uftwf" />

    <tx:annotation-driven transaction-manager="hibernateTransactionManager" />


    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close">

        <!-- these are C3P0 properties -->
        <property name="acquireIncrement" value="${database.acquireIncrement}" />
        <property name="minPoolSize" value="${database.minPoolSize}" />
        <property name="maxPoolSize" value="${database.maxPoolSize}" /> 
        <property name="maxIdleTime" value="${database.maxIdleTime}" />

        <property name="driverClass" value="${database.driver}" />
        <property name="jdbcUrl" value="${database.url}" />
        <property name="user" value="${database.user}" />
        <property name="password" value="${database.password}" />
    </bean>

    <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
        destroy-method="close"> <property name="driverClassName" value="${database.driver}" 
        /> <property name="url" value="${database.url}" /> <property name="username" 
        value="${database.user}" /> <property name="password" value="${database.password}" 
        /> </bean> -->

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>org.uftwf.schoolvisit.model.VisitModel</value>
                <value>org.uftwf.schoolvisit.model.NameID_lookupModel</value>
                <value>org.uftwf.schoolvisit.model.School_lookupModel</value>
            </list>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>


                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
                <prop key="format_sql">${format_sql}</prop>
                <prop key="hibernate.c3p0.min_size">10</prop>
                <prop key="hibernate.c3p0.max_size">25</prop>
                <prop key="hibernate.c3p0.timeout">600</prop>
                <prop key="hibernate.c3p0.max_statements">0</prop>
                <prop key="hibernate.c3p0.idle_test_period">300</prop>
                <prop key="hibernate.c3p0.acquire_increment">5</prop>
            </props>
        </property>
    </bean>

    <bean id="hibernateTransactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
</beans>

why is C3P0 not using the hibernate propertys but using the mysql onces?

You're defining your C3P0 bean with the normal properties. Change ${database...} to the associated key that you want.

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