Results 1 to 6 of 6

Thread: Hibernate: Two Connections for one call???

  1. #1
    Join Date
    Feb 2011
    Posts
    22

    Default Hibernate: Two Connections for one call???

    We are currently debugging a puzzling problem with our database connection pool. It seems that whenever one we make a call to our database, two database connections are checked out of our connection pool. We are having a hard time tracking down what portion of our application might be causing this. We have a spring based application that has DAOs that use the older Spring HibernateTemplate as well as the Spring HibernateTransactionManager and the @Transactional annotation. We are using Hibernate 3.3.1 and c3p0 as our connection pool. We are wondering if there is any sort of configuration that might cause two sessions to be created and therefore, two connections be checked out? Thanks.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Well how about some configuration and code (web.xml, applicationContext etc.).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2011
    Posts
    22

    Default

    Most certainly. Here are the Spring bean configurations for our Hibernate setup. I have removed some of the repetitive configuration settings to keep the size down. My worry is the use of the session factory more than once. If Hibernate is set up to do session per request and we use the session factory twice, would that not create more than once session, and in turn, more than one database connection?

    Code:
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
      <property name="driverClass"> <value>com.mysql.jdbc.Driver</value></property>
    <property name="jdbcUrl"> <value>...</value> </property>
    <property name="user"> <value>...</value> </property>
    <property name="password"> <value>...</value></property>
    <property name="acquireIncrement"><value>10</value></property>
    <property name="idleConnectionTestPeriod"><value>300</value></property>
    <property name="minPoolSize"><value>10</value></property>
    <property name="maxPoolSize"><value>100</value></property>
    <property name="maxStatements"><value>0</value></property>
    <property name="maxIdleTime"><value>10800</value></property>
    </bean>
    
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
            <property name="mappingResources">
            <list>
              ... Hibernate HBM files ...
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
              <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    <prop key="hibernate.show_sql">false</prop>
    <prop key="hibernate.format_sql">false</prop>
            </props>            
        </property>
    </bean>
    	
    <tx:annotation-driven transaction-manager="transactionManager"/>
    
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
          <ref local="sessionFactory"/>
        </property>
    </bean>
    	 
    <bean id="proxyStore" class="net.sf.gilead.core.store.stateless.StatelessProxyStore" />
    
    <bean id="persistenceUtil" class="net.sf.gilead.core.hibernate.spring.HibernateSpringUtil">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>								     
    
    <bean id="persistentBeanManager" class="net.sf.gilead.core.PersistentBeanManager">
        <property name="proxyStore" ref="proxyStore" />
        <property name="persistenceUtil" ref="persistenceUtil" />
    </bean>
    Thanks!
    Last edited by ttmrb; Mar 15th, 2011 at 12:50 PM. Reason: Adding more properties for more clarity

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    For some reason seeing something like HibernateSpringUtil makes me shudder... Why on earth would you need that. Also you left out the properties and those can be quite interesting... (The same goes for your HibernateSpringUtil and how you use/call this class).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Feb 2011
    Posts
    22

    Default

    I have added some additional code to my previous post for more details.

    The HibernateSpringUtil is from Gilead. This enables us to use hibernate enabled objects in GWT. When a hibernate enabled object is transferred over to the client the hibernate specific stuff is stripped away and re-attached when it comes back to the server.

    Hope this helps.

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    There seems nothing wrong with your configuration so there must be something weird going on. Do you have duplicate instances of beans (maybe by accident)? Can you post your data usage code.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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