-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate hanging on SELECT query
PostPosted: Fri May 28, 2010 6:15 am 
Newbie

Joined: Fri May 28, 2010 6:06 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Hibernate hanging on SELECT query
PostPosted: Fri May 28, 2010 6:28 am 
Newbie

Joined: Fri May 28, 2010 6:06 am
Posts: 2
More on this, I've just got some stats from the session factory before every SQL query and there doesn't appear to be a problem with sessions left open:-

Code:
Statistics[start time=1275042445085,sessions opened=0,sessions closed=0,transactions=0,successful transactions=0,optimistic lock failures=0,flushes=0,connections obtained=0,statements prepared=0,statements closed=0,second level cache puts=0,second level cache hits=0,second level cache misses=0,entities loaded=0,entities updated=0,entities inserted=0,entities deleted=0,entities fetched=0,collections loaded=0,collections updated=0,collections removed=0,collections recreated=0,collections fetched=0,queries executed to database=0,query cache puts=0,query cache hits=0,query cache misses=0,max query time=0]


So I'm still flumoxed!


Top
 Profile  
 
 Post subject: Re: Hibernate hanging on SELECT query
PostPosted: Fri May 28, 2010 3:36 pm 
Regular
Regular

Joined: Tue May 11, 2010 5:50 pm
Posts: 54
Location: Norman, Ok, U.S.A
Try getCurrentSession instead of openSession


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.