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>
|