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.  [ 2 posts ] 
Author Message
 Post subject: Bad performance using NamedQuery - What am I not getting
PostPosted: Wed Sep 09, 2009 3:21 pm 
Newbie

Joined: Mon Dec 08, 2008 5:51 pm
Posts: 8
I have a read-mostly application and have elected to use NamedQueries in place of hibernate DAO's.

I execute the following in Oracle, with trace on and the analysis indicates that it completes within 00:00:00 seconds,
it is after all a simple row count:

SELECT count(*) as totalRows
FROM (
SELECT A.KEY Key
FROM
VALUES A
WHERE A.action_date between to_date('9/1/2008', 'MM/DD/YYYY') and to_date('11/30/2008', 'MM/DD/YYYY')
) A

Consistent with the handling of more complex queries, when I save this as a named query and execute it as follows, the execution time takes just over a minute:

Query q = hibernateSession.getNamedQuery("GetCount");
q.setDate("fromDate", rqst.getFromDate());
q.setDate("toDate", rqst.getToDate());
q.setResultTransformer(Transformers.aliasToBean(CountDTO.class));
CountDTO c = (CountDTO) q.uniqueResult();

I am not using any caching strategy. Why would such a simple query take so long?
I wonder if my larger queries are suffering additional performance slow downs.

The Actual Named Query definition is as follows:
<sql-query name="GetCount">
<return-scalar column="totalRows" type="java.lang.Integer"/>
<![CDATA[
SELECT count(*) as totalRows
FROM (
SELECT A.KEY Key
FROM
VALUES A
WHERE A.action_date between :fromDate and :toDate
) A
]]>
</sql-query>


Top
 Profile  
 
 Post subject: Re: Bad performance using NamedQuery - What am I not getting
PostPosted: Wed Sep 09, 2009 4:02 pm 
Newbie

Joined: Mon Dec 08, 2008 5:51 pm
Posts: 8
By rewriting the query to use the SQL Sum and general rearrangement of the sql, the performance was
improved. It wasn't apparently hibernate or named queries, so much as its execution of the query.


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