Results 1 to 4 of 4

Thread: Hibernate Connection Pooling

  1. #1
    Join Date
    Sep 2004
    Posts
    2

    Default Hibernate Connection Pooling

    Hi,

    Before I start describing my issue, I should mention that I am relatively new to spring ..

    We are developing a spring + hibernate application. We have our application setup such that we do not explicitly manage transactions (we let spring manage it for us).

    I am trying to configure connection pooling and towards this I have set the appropriate c3p0 properties (applicationcontext.xml pasted at the end of this mail). But everytime I issue a database command it seems to me that spring is creating a new connection... (Message from log pasted below)

    Sep 24, 2004 11:00:20 AM org.springframework.jdbc.datasource.DriverManagerD ataSource getConnectionFromDriverManager
    INFO: Creating new JDBC connection to [jdbc:oracle:thin:@dev.xyz.com:1521:dev1]

    Why is a new JDBC connection being created each time ? What am I doing worng?

    Best Regards
    Ankur

    Relevant sections of my applicationcontext.xml are pasted below
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="dataSource"> <ref local="dataSource"/> </property>
    <property name="mappingResources">
    <list>
    <value>com/mtgi/cciaws/model/User.hbm.xml</value>
    <value>com/mtgi/cciaws/model/ResourceGroup.hbm.xml</value>
    <value>com/mtgi/cciaws/model/Company.hbm.xml</value>
    <value>com/mtgi/cciaws/model/Usersresgrpxref.hbm.xml</value>
    <value>com/mtgi/cciaws/model/Product.hbm.xml</value>
    <value>com/mtgi/cciaws/model/Productattributes.hbm.xml</value>
    <value>com/mtgi/cciaws/model/Productdependencies.hbm.xml</value>
    <value>com/mtgi/cciaws/model/Package.hbm.xml</value>
    <value>com/mtgi/cciaws/model/Attribute.hbm.xml</value>
    <value>com/mtgi/cciaws/model/Attributevalues.hbm.xml</value>
    <value>com/mtgi/cciaws/model/Security.hbm.xml</value>
    <value>com/mtgi/cciaws/model/Packageproductxref.hbm.xml</value>
    <value>com/mtgi/cciaws/model/Transactionlog.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.O racleDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.c3p0.minPoolSize">5</prop>
    <prop key="hibernate.c3p0.maxPoolSize">20</prop>
    <prop key="hibernate.timeout">1800</prop>
    <prop key="hibernate.max_statement">50</prop>
    </props>
    </property>
    </bean>
    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory"><ref local="sessionFactory"/> </property>
    </bean>

    <!-- BEGIN User Bean Definition -->
    <bean id="userDAO" class="com.mtgi.cciaws.dao.hibernate.UserDAOHibern ate">
    <property name="sessionFactory"><ref local="sessionFactory"/> </property>
    </bean>

    <bean id="userManagerTarget" class="com.mtgi.cciaws.service.impl.UserManagerImp l">
    <property name="userDAO"><ref local="userDAO"/> </property>
    <property name="validator"><ref bean="userValidator"/> </property>
    </bean>

    <bean id="userValidator" class="com.mtgi.cciaws.web.UserValidator"/>

    <bean id="userManager" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref local="transactionManager"/> </property>
    <property name="target"><ref local="userManagerTarget"/> </property>
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>
    <!-- END User Bean Definition -->

    </beans>

  2. #2
    Join Date
    Sep 2004
    Posts
    18

    Default

    It seems to me you haven't defined your datasource anywhere, so I'm not even sure where your JDBC connections are coming from right now.

    Wouldn't it be better to simply define a pooling DataSource (like DBCP, don't know whether C3P0 has one)?

    Carl-Eric

  3. #3
    Join Date
    Sep 2004
    Posts
    2

    Default

    My apologies..

    The database connection information is being read out of a properties files... The contents of the same are pasted below...

    login.keyLocation=C:\\key.jks
    interface.protocol=https://
    interface.hostname=dev.xyz.com
    interface.path=
    interface.service=
    jdbc.driverClassName=oracle.jdbc.driver.OracleDriv er
    jdbc.url=jdbc:oracle:thin:@dev.xyz.com:1521:dev1
    jdbc.jndiname=jdbc/oracleattws
    jdbc.username=bogus_user
    jdbc.password=bogus_password

    Also, here is the portion of the applicationcontext.xml which shows the database connections...

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location">
    <value>/WEB-INF/classes/application.properties</value>
    </property>
    </bean>

    <bean id="applicationProps" class="com.mtgi.cciaws.util.CCIGlobal">
    <property name="keyLocation"> <value>${login.keyLocation}</value> </property>
    <property name="protocol"> <value>${interface.protocol}</value> </property>
    <property name="hostname"> <value>${interface.hostname}</value> </property>
    <property name="path"> <value>${interface.path}</value> </property>
    <property name="service"> <value>${interface.service}</value> </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <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>
    </bean>

  4. #4
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    But everytime I issue a database command it seems to me that spring is creating a new connection
    Spring Transaction Management Layer uses a new connection each time a transaction starts and close it when the transaction ends. The connection may be a new one created using JDBC DriverManager or recycled from a DataSource.

    Sep 24, 2004 11:00:20 AM org.springframework.jdbc.datasource.DriverManagerD ataSource getConnectionFromDriverManager
    INFO: Creating new JDBC connection to [jdbc:oracle:thin:@dev.xyz.com:1521:dev1]
    It seems that your are using Spring Framework DriverManagerDataSource, this class is an implementation of SmartDataSource that is sweetable for test and development environment, not for production.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

Similar Threads

  1. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  2. Spring/Hibernate connection pooling
    By graeder in forum Data
    Replies: 4
    Last Post: Jun 13th, 2005, 06:29 AM
  3. Replies: 0
    Last Post: Apr 6th, 2005, 08:24 AM
  4. Unclosed Hibernate Connection
    By jvargas in forum Data
    Replies: 4
    Last Post: Mar 28th, 2005, 01:24 PM
  5. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •