-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Opening JDBC connection - No response after this
PostPosted: Wed Feb 24, 2010 1:30 pm 
Newbie

Joined: Wed Feb 24, 2010 1:05 pm
Posts: 5
Location: India
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:
------
Code:
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
------------------------------
Code:
<!-- 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.PropertiesFactoryBean">
      <property name="properties">
         <props>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</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">false</prop>
         </props>
      </property>
   </bean>

   <bean id="mySessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <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
----------------
Code:
package com.eginnovations.license.dao;

import java.util.List;

import javax.sql.DataSource;
import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;

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


Top
 Profile  
 
 Post subject: Re: Opening JDBC connection - No response after this
PostPosted: Thu Feb 25, 2010 4:11 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Probably you reached already the maximum of sessions (hibernate.c3p0.maxPoolSize)
or the database is not able to supply further connections.

As you use c3p0 you should take a look what c3p0 is logging
http://www.mchange.com/projects/c3p0/index.html#configuring_logging
This logging should give you informations about the real cause of the problem.

N.B.: You can also let c3p0 register to JMX MBeanServer, so at runtime you can
control and mange the connection pool via jconsole
http://www.mchange.com/projects/c3p0/index.html#jmx_configuration_and_management


Top
 Profile  
 
 Post subject: Re: Opening JDBC connection - No response after this
PostPosted: Thu Feb 25, 2010 5:25 am 
Newbie

Joined: Wed Feb 24, 2010 1:05 pm
Posts: 5
Location: India
Thanks.
I will check and let you know the results.


Top
 Profile  
 
 Post subject: Re: Opening JDBC connection - No response after this
PostPosted: Thu Feb 25, 2010 5:47 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
It could also help to issue
jstack <javavm-pid>
taking a look at the stacktrace where the code is executing.
It might also be that the query is already being executed and the database server is delaying the answer.


Top
 Profile  
 
 Post subject: Re: Opening JDBC connection - No response after this
PostPosted: Thu Mar 25, 2010 7:16 am 
Newbie

Joined: Thu Mar 25, 2010 7:10 am
Posts: 1
Hi, i'm facing the same issue. Did you solve it?


Top
 Profile  
 
 Post subject: Re: Opening JDBC connection - No response after this
PostPosted: Wed Feb 02, 2011 4:45 pm 
Newbie

Joined: Wed Feb 02, 2011 4:35 pm
Posts: 1
Hi, you have to add some parameters in your DataSource:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="maxIdle" value="-1"></property>
<property name="maxActive" value="-1"></property>
<property name="maxOpenPreparedStatements" value="-1"></property>
<property name="maxWait" value="30000"></property>
<property name="validationQuery" value="SELECT 1"></property>
<property name="testOnBorrow" value="true"></property>

</bean>

you can modify the parameters maxIdle,maxActive,maxOpenPreparedStatements and maxWait.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.