I'm trying to implement C3PO in my spring supported application (Hibernate 2.1.3 - MySQL 4.1).
This was the original state of my DataSource entry in the applicationContext.xml.
My idea was to use
com.mchange.v2.c3p0.ComboPooledDataSource instead of
org.apache.commons.dbcp.BasicDataSource
But when I just changed this, it complained that the properties were nonWritable. After commenting them, it tried to use the c3po connection pooling but threw an error that my url couldn't be null. What was expected since I didn't specify it.
My question, where can I specify this url? Cause the only references I have on c3po connection pooling is in this applicationContect.xml and in my hibernate.cfg.xml. Or is there perhaps a better way to implement c3po in my spring application?
I guess I just forgot something, but after staring myself blind on documentation, forum posts, ... I decided to ask for help.
applicationContext.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!--
Datasource that works in any application server
You could easily use J2EE data source instead if this were
running inside of a J2EE container.
-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
<property name="url"><value>jdbc:mysql:///ngb</value></property>
<property name="username"><value>root</value></property>
<property name="password"><value></value></property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="configLocation">
<value>hibernate.cfg.xml</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
...
</beans>
Hibernate.cfg.xmlCode:
<hibernate-configuration>
<session-factory>
...
<property name="c3p0.initialPoolSize">1</property>
<property name="c3p0.minPoolSize">5</property>
<property name="c3p0.maxPoolSize">20</property>
<property name="c3p0.timeout">45000</property>
<property name="c3p0.max_statements">50</property>
<property name="c3p0.validate">false</property>
<property name="connection.provider_class">net.sf.hibernate.connection.C3P0ConnectionProvider</property>
...
</session-factory>
</hibernate-configuration>
If you have need of any more code our info, please tell me.
Thanks in advance.