首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

hibernate查询慢,怎么处理?

2013-12-11 
hibernate查询慢,怎么办?????我的customer表中有两千万条数据 采用hibernate分页查询,每页8条要1分钟才能

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

查询代码如下:
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
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=?




[解决办法]
一般都不会使用hql语句进行查询操作的,都是写sql
[解决办法]
这个要用原生sql

热点排行