My app runs for quite some time, but after a certain number of queries, it hangs. I wonder if this is to do with my session not closing properly but I've look at my code and configuration and can't see anything wrong:
Code here:-
Code:
/**
*
*/
package com.cmmgroup.daos;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
import com.cmmgroup.db.phoebus.PhoebusTRRecord;
/**
* @author cmmcr2
*
*/
public class AccountDAOImpl implements AccountDAO {
private HibernateTemplate template;
public void setSessionFactory(SessionFactory sf) {
this.template = new HibernateTemplate(sf);
}
public long getAccountInternalReference(Long acctNo) {
Session s = this.template.getSessionFactory().openSession();
Query query = s.createSQLQuery(
"select ACCT001 from ACCT where ACCT010= :acctNo")
.setParameter("acctNo", acctNo);
Long result = ((BigDecimal) query.uniqueResult()).longValue(); //HANGS ON THIS STATEMENT
s.close();
return result;
}
}
Configuration here:-
Code:
<bean id="org.hibernate.SessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.bytecode.provider">javassist</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.use_second_level_cache">
false
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.c3p0.max_size">15</prop>
<prop key="hibernate.c3p0.min_size">3</prop>
<prop key="hibernate.c3p0.timeout">5000</prop>
<prop key="hibernate.c3p0.max_statements">100</prop>
<prop key="hibernate.c3p0.idle_test_period">300</prop>
<prop key="hibernate.c3p0.acquire_increment">2</prop>
</props>
</property>
</bean>
End of the Log output here:-
Code:
DEBUG - ConnectionManager.openConnection(444) | opening JDBC connection
DEBUG - SQLStatementLogger.logStatement(111) | select ACCT001 from ACCT where ACCT029 = 'L' and ACCT011 <> 'C' and ACCT303 = '130' and ACCT014 like '%Collection%' and ACCT514 <= ? and ACCT003 = ?
Hibernate: select ACCT001 from ACCT where ACCT029 = 'L' and ACCT011 <> 'C' and ACCT303 = '130' and ACCT014 like '%Collection%' and ACCT514 <= ? and ACCT003 = ?
DEBUG - Loader.bindNamedParameters(1768) | bindNamedParameters() java.util.GregorianCalendar[time=1274828400000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/London",offset=0,dstSavings=3600000,useDaylight=true,transitions=242,lastRule=java.util.SimpleTimeZone[id=Europe/London,offset=0,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2010,MONTH=4,WEEK_OF_YEAR=21,WEEK_OF_MONTH=4,DAY_OF_MONTH=26,DAY_OF_YEAR=146,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=3600000] -> startDate [1]
DEBUG - Loader.bindNamedParameters(1768) | bindNamedParameters() WF -> portfolio [2]
DEBUG - AbstractBatcher.logOpenResults(426) | about to open ResultSet (open ResultSets: 0, globally: 0)
DEBUG - AbstractBatcher.logCloseResults(433) | about to close ResultSet (open ResultSets: 1, globally: 1)
DEBUG - AbstractBatcher.logClosePreparedStatement(418) | about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG - StatefulPersistenceContext.initializeNonLazyCollections(860) | initializing non-lazy collections
DEBUG - ConnectionManager.afterTransaction(325) | transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
DEBUG - SessionImpl.<init>(247) | opened session at timestamp: 12750375198
DEBUG - AbstractBatcher.logOpenPreparedStatement(410) | about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG - ConnectionManager.openConnection(444) | opening JDBC connection
As you will see the last logging statement is when it tries to open the JDBC connection.
Any ideas what could be causing this ? I get the same problem regardless of whether I use the Hibernate or C3p0 connection manager