If you use Spring, which is a good idea, here is the way Hibernate is feeded with dbcp source info.
First a dataSource is created in the config.xml file of Spring:
Code:
<bean id="dbcpDataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
lazy-init="true">
<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
<property name="removeAbandoned">
<value>true</value>
</property>
<property name="removeAbandonedTimeout">
<value>30</value>
</property>
<property name="minIdle">
<value>3</value>
</property>
<property name="initialSize">
<value>1</value>
</property>
<property name="maxActive">
<value>40</value>
</property>
<property name="maxWait">
<value>5000</value>
</property>
</bean>
Then this pool is injected in the HibernateSessionFactory :
Code:
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
lazy-init="true">
<property name="sessionFactory">
<ref local="hibernateSessionFactory" />
</property>
<property name="dataSource">
<ref bean="dbcpDataSource" />
</property>
</bean>
so that now, HIbernate knows WHERE to get a connection from the pool.
You see in this code how you can tune your pool for optimization.