-->
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.  [ 1 post ] 
Author Message
 Post subject: Select Count(*) Very Slow
PostPosted: Sun Nov 13, 2011 4:42 pm 
Newbie

Joined: Sun Nov 13, 2011 4:35 pm
Posts: 6
Hi Guys i have a problem and i need help i am hibernate newbie.. i am doing a small Java ee aplication.

i am doing a Select count(*) from a bunch of tables but is very slow.. here is my code..
Code:
         
          StringBuilder Hql = new StringBuilder("Select Count(*)");
           Hql.append(" from Detalle D ");
           Hql.append("inner join  D.Factura.Cliente C");
           Hql.append(" where (D.Factura.Fecha >=:startDate And D.Factura.Fecha <=:endDate)");
           Hql.append(" And (D.Producto.IdLinea=:idLinea)");
           if(!idSucursal.equals(-1)) Hql.append("And (C.Sucursal.Id=:idSucursal)");           
           Hql.append(" Group by  D.Producto.Id");
           Hql.append(",D.Producto.Name,D.Factura.Cliente.Sucursal.Zona");
           Hql.append(",D.Factura.Cliente.Sucursal.Id");       
           Query Query = Session.createQuery(Hql.toString());
           Query.setParameter("startDate",StartDate);
           Query.setParameter("endDate",EndDate);
           Query.setParameter("idLinea",idLinea);
           if(!idSucursal.equals(-1)) Query.setParameter("idSucursal",idSucursal);
           Query.setCacheable(true);
           Count = Query.list().size();

i am getting the next CPU. times..
Hibernate. Count: 3453ms..
Directly against DB. 850 ms.
Using JDBC. 1000 ms..
why this is so slow..
please give a hand..
by the way. i am using postgres 8.4 and the groups i am using they are necessary.
sorry by my poor english.best regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.