Announcement Announcement Module
Collapse
No announcement yet.
Opening JDBC connection - No response after this Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Opening JDBC connection - No response after this

    Hi,
    I have a web application powered by struts 2-Spring-hibernate. It is working fine in all screens. After some time, when I press submit button to fetch the results, hibernate hangs while opening a connection. It hangs for hours. no error messages are written in the log.

    LOG:
    ------
    16:58:14,144 DEBUG SessionFactoryUtils:316 - Opening Hibernate Session
    16:58:14,144 DEBUG SessionImpl:220 - opened session at timestamp: 12670306941
    16:58:14,144 DEBUG BaseDAO:60 - getting list from crit
    16:58:14,144 DEBUG AbstractBatcher:366 - about to open PreparedStatement (open PreparedStatements: 0, globally: 1)
    16:58:14,159 DEBUG ConnectionManager:421 - opening JDBC connection
    SPRING BEAN CONFIGURATION
    ------------------------------
    <!-- DAO BEANS -->
    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/license_dev" />
    <property name="username" value="root" />
    <property name="password" value="" />
    </bean>

    <bean id="myHibernateProperties"
    class="org.springframework.beans.factory.config.Pr opertiesFactoryBean">
    <property name="properties">
    <props>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    <prop key="hibernate.query.substitutions">true 'T', false 'F'</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.c3p0.timeout">600</prop>
    <prop key="hibernate.c3p0.max_statement">50</prop>
    <prop key="hibernate.c3p0.testConnectionOnCheckout">fals e</prop>
    </props>
    </property>
    </bean>

    <bean id="mySessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource">
    <ref local="myDataSource" />
    </property>
    <property name="hibernateProperties">
    <ref bean="myHibernateProperties" />
    </property>
    <!-- OR mapping files. -->
    <property name="mappingResources">
    <list>
    <value>entity.hbm.xml</value>
    </list>
    </property>
    </bean>
    <bean id="baseDAO" class="com.eginnovations.license.dao.BaseDAO"
    autowire="byType">
    <property name="dataSource" ref="myDataSource" />
    <property name="sessionFactory" ref="mySessionFactory" />
    </bean>
    BASE DAO CLASS
    ----------------
    package com.eginnovations.license.dao;

    import java.util.List;

    import javax.sql.DataSource;
    import org.apache.log4j.Logger;
    import org.springframework.orm.hibernate3.support.Hiberna teDaoSupport;
    import org.springframework.transaction.annotation.Transac tional;

    public class BaseDAO extends HibernateDaoSupport implements IBaseDAO {
    protected Logger logger = Logger.getLogger(BaseDAO.class);
    protected DataSource dataSource;

    public void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
    }

    @Transactional
    public void save(Object entity){
    logger.info("Saving object:"+entity);
    super.getHibernateTemplate().save(entity);
    logger.info("Object save successful:"+entity);
    }

    @SuppressWarnings("unchecked")
    @Transactional
    public List<Object> list(String qry) {
    return (List<Object>) super.getHibernateTemplate().find(qry);
    }

    @SuppressWarnings("unchecked")
    @Transactional
    public List<Object> list(String qry, Object[] object) {
    return (List<Object>) super.getHibernateTemplate().find(qry, object);
    }
    }


    Any help will be appreciated.

    Thanks

  • #2
    Probably not Spring

    Usually this kind of problem is to do with the connection pool or the database itself.

    This StackOverflow article discusses a similar issue.

    Also, take a look at the C3PO manual regarding recovery from broken connections.

    Comment


    • #3
      First off all your c3po settings in hibernate are useless as you are injecting a DataSource, so start by removing those.

      I see the @Transactional annotation but I don't see a tx:annotation-driven nor a HibernateTransactionManager.

      Code:
      <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      	<property name="driverClassName" value="com.mysql.jdbc.Driver" />
      	<property name="url" value="jdbc:mysql://localhost:3306/license_dev" />
      	<property name="username" value="root" />
      	<property name="password" value="" />
      </bean>
      
      <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      	<property name="dataSource" ref="myDataSource" />
      	<property name="hibernateProperties">
      		<props>
      			<prop key="hibernate.hbm2ddl.auto">update</prop>
      			<prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
      			<prop key="hibernate.query.substitutions">true 'T', false 'F'</prop>
      			<prop key="hibernate.show_sql">true</prop>
      		</props>
      	</property>
      	<!-- OR mapping files. -->
      	<property name="mappingResources">
      		<list>
      			<value>entity.hbm.xml</value>
      		</list>
      	</property>
      </bean>
      
      <bean id="baseDAO" class="com.eginnovations.license.dao.BaseDAO" autowire="byType">
      	<property name="dataSource" ref="myDataSource" />
      	<property name="sessionFactory" ref="mySessionFactory" />
      </bean>
      Next to that you are injecting a datasource directly, which means to me you are using that directly, as soon as you do this and retrieve resources you also need to take care of resource management yourself, because spring stops here.

      First implement transactions correctly it seems there is something missing there, without it no prober resource handling is done. Next to that if you need/use the datasource use it from a JdbcTemplate that way it rides on springs transaction management.

      You state you are using struts, how are you obtaining the needed references in your actions?
      Last edited by Marten Deinum; Feb 25th, 2010, 03:59 AM.

      Comment


      • #4
        Thanks both of you!
        It is purely connection pool issue.

        I need 8 ~ 15 connections, where the default connection was 8.

        I made my service methods as transactional, increased the connection pool size, now it is working fine.

        Comment

        Working...
        X