Java 在Hibernate中使用SpringWebflow进行C3P0池仍然没有成功

Java 在Hibernate中使用SpringWebflow进行C3P0池仍然没有成功,java,spring,hibernate,spring-mvc,c3p0,Java,Spring,Hibernate,Spring Mvc,C3p0,使用SpringWebFlow在Hibernate中使用C3P0池仍然没有成功如果我使用下面的database.xml文件并运行我的项目,我检查数据库,只看到两个连接到它,但我将它设置为10 database.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2

使用SpringWebFlow在Hibernate中使用C3P0池仍然没有成功如果我使用下面的database.xml文件并运行我的项目,我检查数据库,只看到两个连接到它,但我将它设置为10

database.xml

<?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">
        <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="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>

org.uftwf.schoolvisit.model.VisitModel
org.uftwf.schoolvisit.model.NameID\u lookupModel
org.uftwf.schoolvisit.model.School\u lookupModel
${hibernate.dial}
${hibernate.show_sql}
${hibernate.use\u sql\u comments}
${format_sql}
10
25
600
0
300
5.
但是如果我使用这个database.xml文件,我将看到10个连接到数据库,但是我希望hibernate管理池,那么有人能告诉我为什么上面的database.xml不工作,而下面的一个工作吗

database.xml:

<?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="idleConnectionTestPeriod" value="300" />

        <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="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>

org.uftwf.schoolvisit.model.VisitModel
org.uftwf.schoolvisit.model.NameID\u lookupModel
org.uftwf.schoolvisit.model.School\u lookupModel
${hibernate.dial}
${hibernate.show_sql}
${hibernate.use\u sql\u comments}
${format_sql}
10
25
600
0
300
5.

为什么要hibernate管理池?第二种情况下的设置方式是使用spring配置dataSource&hibernate会话工厂的正确方式。这将在spring事务管理中正常工作

当您将数据源作为参数传递给sessionFactoryBean时,与数据源配置相关的hibernate属性将被忽略。如果坚持使用hibernate管理池,可以尝试删除AnnotationSessionFactoryBean中的dataSource属性注入。现在需要将driverClass、jdbcURL等指定为hibernate属性的一部分

来自SpringJavadoc

设置SessionFactory要使用的数据源。如果设置,这将 覆盖Hibernate属性中的相应设置。如果这是 设置时,Hibernate设置不应定义连接提供程序 避免无意义的双重配置

)


您可以让spring管理连接池(通过配置数据源bean并将其传递给sessionFactory),也可以让hibernate完全管理它。Half&Half将不起作用。

如果我们使用HibernateDaoSupport类,spring会自动管理连接池吗?如果是,最小和最大连接是什么?