I have a strange problem with my application, running on JBoss 6.1, which uses Hibernate and Spring. I'm also using c3p0 to have connection pooling.
I have a datasource defined under JBoss. The datasource is a C3P0PooledDataSource. Please note that maxpoolsize is 20 and initial pool size is also 20.
<mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource"
name="jboss.jca:service=DataSourceBinding,name=db/MED_POOLED">
<attribute name="JndiName">java:db/MED_POOLED</attribute>
<attribute name="JdbcUrl">jdbc:oracle:thin:@dbhost:1521:SID</attribute>
<attribute name="DriverClass">oracle.jdbc.driver.OracleDriver</attribute>
<attribute name="User">xxx</attribute>
<attribute name="Password">xxx</attribute>
<attribute name="AutomaticTestTable">POOL_TEST</attribute>
<attribute name="CheckoutTimeout">30000</attribute>
<attribute name="Description">Pooled Datasource for med</attribute>
<attribute name="IdleConnectionTestPeriod">180</attribute>
<attribute name="InitialPoolSize">20</attribute>
<attribute name="MaxPoolSize">20</attribute>
<attribute name="MinPoolSize">20</attribute>
<attribute name="TestConnectionOnCheckin">true</attribute>
<attribute name="MaxIdleTime">3600</attribute>
<depends>jboss:service=Naming</depends>
</mbean>
In my spring configuration file, datasource is retrieved using the jndi name:
<bean id="defaultDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>db/MED_POOLED</value></property>
</bean>
and then used to build a LocalSessionFactoryBean
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="defaultDataSource"/>
<property name="namingStrategy" ref="namingStrategy"/>
<property name="configLocations">
<list>
<value>classpath:hibernate.cfg.xml</value>
<value>classpath:jbpm.hibernate.cfg.xml</value>
</list>
</property>
<property name="mappingDirectoryLocations">
<list><value>WEB-INF/classes</value></list>
</property>
</bean>
In hibernate.cfg.xml no datasource is defined, so the dataSource property of org.springframework.orm.hibernate3.LocalSessionFactoryBean should be used.
When I start my application server, something strange happens (al least, strange to me):
JBoss starts, I see in the log this line
[com.mchange.v2.c3p0.jboss.C3P0PooledDataSource] Bound C3P0 PooledDataSource to name'java:db/MED_POOLED'. Starting...
and if I check on database, 20 sessions are present.
- When the LocalSessionFactoryBean is created, suddendly 40 connections are present on Db, but in my datasource configuration I specified to create at maximum 20 connections.
I think that, in some way, the datasource is reinitialized when the LocalSessionFactoryBean is created, but I don't understand why, and when JBoss is started I have exactly double the connections I want.
Do you know what's happening? Is there something wrong with my configuration?
I'm using JBoss 6.1, the latest available version of c3p0 (0.9.5), Spring 3.0.3.RELEASE and Hibernate 3.5.3-Final
org.springframework
package and see if anything unusual stands out from the logs. – Andrei Stefan