日期:2014-05-17  浏览次数:21165 次

hibernate查询慢,怎么办?????
我的customer表中有两千万条数据 采用hibernate分页查询,每页8条要1分钟才能查出来;怎么提高查询速度呢???

查询代码如下:
public Object doInHibernate(Session session)
throws HibernateExceptionSQLException {
Query qu=session.createQuery("from Customer order by createtime desc");
int pno=pas.getPno();
int psize=pas.getPsize();
qu=qu.setFirstResult((pno-1)*psize).setMaxResults(psize);
List<Customer> li=qu.list();
pas.setCustomers(li);
return pas;


打印的sql:
其中下面的sql 有两条
select
        * 
    from
        ( select
            customer0_.CID as CID1_,
            customer0_.CUSTNAME as CUSTNAME1_,
            customer0_.CUSTPASSWORD as CUSTPASS3_1_,
            customer0_.CUSTSEX as CUSTSEX1_,
            customer0_.CUSTAGE as CUSTAGE1_,
            customer0_.CREATETIME as CREATETIME1_,
            customer0_.UPDATETIME as UPDATETIME1_,
            customer0_.CREATEMAN as CREATEMAN1_ 
        from
            SCOTT.CUSTOMER customer0_ 
        order by
            customer0_.CREATETIME desc ) 
    where
        rownum <= ?

而这条sql 有16条
 select
        order0_.custid as custid1_,
        order0_.O_ID as O1_1_,
        order0_.O_ID as O1_2_0_,
        order0_.ORDERPRICE as ORDERPRICE2_0_,
        order0_.CUSTID as CUSTID2_0_,
        order0_.ORDERTIME as ORDERTIME2_0_,
        order0_.ORDERSTAT as ORDERSTAT2_0_,
        order0_.CREATETIME as CREATETIME2_0_,
        order0_.UPDATETIME as UPDATETIME2_0_,
        order0_.CREATEMAN as CREATEMAN2_0_,
        order0_.custid as custid2_0_ 
    from
        SCOTT.ORDERS order0_ 
    where
        order0_.custid=?



提高hibernate查询速度