Hibernate version: 3.2.5ga, hibernate-c3p0 3.3.0ga
c3p0 version: 0.9.1.2
Tomcat version: 6.0.18
Hibernate.cfg.xml mapping:
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/TESTDB</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
context.xml
<context>
<ResourceLink name="jdbc/TESTDB" global="jdbc/TESTDB" type="javax.sql.DataSource" />
</context>
Global resource in server.xml
<Resource auth="Container"
description="DB Connection"
driverClass="org.gjt.mm.mysql.Driver"
maxPoolSize="4" minPoolSize="2" acquireIncrement="1"
name="jdbc/TESTDB" user="rp_dbo" password="darmis"
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:mysql://localhost:3306/testdb" />
Stacktrace:
15:18:19,460 INFO C3P0ConnectionProvider:81 - C3P0 using driver: null at URL: null
15:18:19,460 INFO C3P0ConnectionProvider:82 - Connection properties: {}
15:18:19,460 INFO C3P0ConnectionProvider:85 - autocommit mode: false
15:18:19,460 WARN C3P0ConnectionProvider:88 - No JDBC Driver class was specified by property hibernate.connection.driver_class
Problem:
When configureing Hibernate to use C3P0ConnectionProvider instead of default connectionprovider it seems like Hibernate does not find my configured datasource.
If I remove C3P0ConnectionProvider from my hibernate configuration file, hibernate will find my resource and my test application can handle database transactions. When I try to use C3P0 by adding hibernate.connection.provicer_class C3P0ConnectionProvider it fails to find my datasource.
If I use C3P0ConnectionProvider and configure my datasource with driver_class, url, username and password in my hibernate config file. Hibernate will use C3P0 and it all works fine. So it seems like C3P0ConnectionProvider cannot be configured to use datasource configured in tomcat.
Any idea what i’m doing wrong?
|