I do this on a legacy project. It ain't pretty. My solution was to let to let the container provide the connection via JNDI. Then Torque and Hibernate both use the same connection pool. They are used in separate parts of the application and map to different tables/classes.
I use Tomcat 5, with the built in DBCP connection pool. My Hibernate settings are:
Code:
hibernate.connection.datasource = java:comp/env/jdbc/database_connection
hibernate.dialect = net.sf.hibernate.dialect.MySQLDialect
My Tomcat settings are:
Code:
torque.database.default=default
torque.database.default.adapter=mysql
torque.dsfactory.default.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
torque.dsfactory.default.jndi.path=java:comp/env/jdbc/database_connection
torque.idbroker.cleverquantity=true
My web.xml reads: (in part)
Code:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/database_connection</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
and my context definition (for Tomcat) reads:
Code:
<Context path="/marketing" docBase="marketing" debug="0" reloadable="false">
<Resource name="jdbc/database_connection"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/database_connection">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>5</value>
</parameter>
<!-- 0 = wait -->
<parameter>
<name>whenExhaustedAction</name>
<value>0</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<value>600</value>
</parameter>
<parameter>
<name>testOnBorrow</name>
<value>true</value>
</parameter>
<parameter>
<name>validationQuery</name>
<value>SELECT 1</value>
</parameter>
<!-- MySQL dB username and password for dB connections -->
<parameter>
<name>username</name>
<value></value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<!-- Class name for mm.mysql JDBC driver -->
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<!-- The JDBC connection url for connecting to your MySQL dB.
The autoReconnect=true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
-->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/db</value>
</parameter>
</ResourceParams>
</Context>