Results 1 to 6 of 6

Thread: Problems configuring C3P0 via DataSource

  1. #1

    Default Problems configuring C3P0 via DataSource

    I'm having trouble configuring C3P0 as a datasource. I am configuring it as a separate data source bean and passing that into my session factory. The problem I'm having is that the instance of the ComboPooledDataSource is not picking up the properties I'm setting. Here's how I have the C3P0 connection pool configured and my session factory:

    Code:
    <bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
            destroy-method="close">
            <property name="driverClass" value="${jdbc.driver.classname}"/>
            <property name="jdbcUrl" value="${jdbc.url}"/>
            <!--
            <property name="user" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
            -->
            <property name="properties">
                <props>
                    <prop key="c3p0.acquire_increment">5</prop>
                    <prop key="c3p0.idle_test_period">100</prop>
                    <prop key="c3p0.max_size">100</prop>
                    <prop key="c3p0.max_statements">0</prop>
                    <prop key="c3p0.min_size">10</prop>
                    <prop key="user">${jdbc.username}</prop>
                    <prop key="password">${jdbc.password}</prop>
                </props>
            </property>
        </bean>
    
        <!-- property variables are pulled from hibernate.properties -->
    	<bean id="sessionFactory"
    		  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource" ref="c3p0DataSource"/>
    		<property name="mappingResources">
    			<list>
    				<!-- mapping files taken out for brevity -->
    			</list>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
    				<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                    <!-- provides jmx statistics -->
                    <prop key="hibernate.generate_statistics">true</prop>
                </props>
    		</property>
    		<property name="eventListeners">
    			<map>
    				<entry key="merge">
    					<!-- allow hibernate's merge() method to update ID of the object,
    					in case the object was transient (and hence there was no ID)
    					The cost is that the merge() call now must incur a database call
    					(to generate the ID in database) -->
    					<bean
    						class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
    				</entry>
    			</map>
    		</property>
    	</bean>
    What I'm observing in the logs is when the ComboPooledDataSource gets initialized it only starts up with 3 connections in it's pool, instead of 10 as I'd configured it, and when it increments the number of connections it increments by 3, instead of by 5.

    Here's the debug statement which I think is telling me about the ComboPooledDataSource:

    Code:
    trace com.mchange.v2.resourcepool.BasicResourcePool@8a129d [managed: 3, unused: 3, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@4ec1eb

    Could someone tell me what I'm doing wrong?

    Thanks,
    Christian

  2. #2

    Default Follow up post

    Just as a follow up I should mention that it is actually picking up the user and password properties and properly connecting, which is weird. The other properties though just aren't getting set.

    Are those property keys (which I got from an example on these forums) out of date or something?

    Christian

  3. #3
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    I recall having a similar problem - I actually solve it after looking at the sources. IIRC, setting the user/password overrides the properties set or the other way around - basically a setter erases some previous values.
    In my case, after playing around looking at the source was the easy way to see what is going on.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  4. #4
    Join Date
    May 2005
    Posts
    394

    Default

    Don't use
    <property name="properties">
    but use the setter directly
    <property name="maxPoolSize" value="10" />
    and it works.

  5. #5
    Join Date
    Jun 2006
    Posts
    3

    Default Try this

    The example given doesn't work with c3p0 0.9.1.2. The following does (the values are for debugging purposes of producing one connection and one connection only).

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="user" value="${db.username}"/>
    <property name="password" value="${db.password}"/>
    <property name="driverClass" value="${db.driverClassName}"/>
    <property name="jdbcUrl" value="${db.url}"/>
    <property name="initialPoolSize" value="0"/>
    <property name="maxPoolSize" value="1"/>
    <property name="minPoolSize" value="1"/>
    <property name="acquireIncrement" value="1"/>
    <property name="acquireRetryAttempts" value="0"/>
    </bean>

  6. #6
    Join Date
    Jun 2010
    Posts
    11

    Default This works

    Above mentioned solutions really works..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •