-->
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: Count Query Slow in Hibernate, Fast in JDBC
PostPosted: Wed Sep 01, 2004 5:46 pm 
Beginner
Beginner

Joined: Thu Nov 20, 2003 1:30 pm
Posts: 27
Hibernate 2.1.4
Sybase 12.5

When I run this select count(*) via hibernate it takes a long time. Over 2 minutes. When I run the EXACT same query that hibernate generates, just via JDBC it runs as expected, less than a second. (I ran this test in the same place I ran the hibernate query, even retrieved the Connection via the same Session.connection(), so the environment was exactly the same).

I was thinking it had something to do with the transaction isolation, but doing a select @@isolation returns 1, right before running the query.

I'm at a complete loss here. Is there anything I can look at or try to figure out why running the select count(*) in hibernate takes SUCH a long time? Could Hibernate or C3P0 be setting the isolation level before and right after the query is done?

Thanks!



Code:
Query query = session.getNamedQuery("selectCountSurveyBatchEmailsQueued");

query.setParameter("survey", surveyBatches[0].getSurvey());
query.setParameter("xsurvey", surveyBatches[0].getSurvey());
query.setParameterList("batchNos", batchNos);
query.setParameterList("xbatchNos", batchNos);
query.setParameterList("completionStatuses", completionStatuses);
query.setParameter("email", email);

List list = query.list();
count = (Integer) list.get(0);

<query name="selectCountSurveyBatchEmailsQueued">
<![CDATA[
   SELECT count(*)
   FROM PanelSurvey panelSurvey
    WHERE panelSurvey.survey=:survey AND panelSurvey.batchNo IN (:batchNos)
       AND panelSurvey.completionStatus IN (:completionStatuses)
       AND panelSurvey.panel NOT IN (
          SELECT panelSurveyEmailLog.panel
          FROM PanelSurveyEmailLog panelSurveyEmailLog
         WHERE panelSurveyEmailLog.email=:email AND panelSurveyEmailLog.survey=:xsurvey
            AND panelSurveyEmailLog.batchNo IN (:xbatchNos))
]]>
</query>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 01, 2004 7:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
strange. the only thing hibernate does is start a transaction, unless you have set hibernate.connection.isolation


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 5:39 pm 
Beginner
Beginner

Joined: Thu Nov 20, 2003 1:30 pm
Posts: 27
Its been a while, but I found the problem (mostly). When I use Sybase's jconnect 5.5 or 6.0 my queries seem to run very slow. As if its setting the transaction isolation level or something strange is going on. But if I use the jTds driver http://jtds.sourceforge.net/ everything works fine! Thats all I changed. Been trying to debug the problem, but haven't gotten anywhere. If anyone has any suggestions let me know.

Thanks


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.