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.