Hibernate 之Criteria Example HQL 分析

      Session s = HibernameUtil.getSession();
         s.beginTransaction();
      
     // QBC
List<Customer> cs = s.createCriteria(Customer.class).add( Restrictions.like("realName", "sex", MatchMode.ANYWHERE)) .list();
     // HQL
List
<Customer> css = s.createQuery( "from Customer c where c.realName like '%sex%'").list();
     // QBE
     Customer entity
= new Customer(); entity.setUserName("www"); Example e = Example.create(entity).excludeZeroes().enableLike( MatchMode.ANYWHERE).excludeZeroes(); List<Customer> csss = s.createCriteria(Customer.class).add(e).list();
s.getTransaction().commit(); s.close();

 

今天 试验了一下 QBC QBE HQL 的速度。很片面但是足以说明问题。

 Hibernate:
    select
        this_.id as id0_0_,
        this_.user_name as user2_0_0_,
        this_.password as password0_0_,
        this_.real_name as real4_0_0_
    from
        customer this_
    where
        (
            this_.user_name like ?
        )
101000
用了这么: 2843

同样是取出 101000条记录  QBE 的速度是最快的。。

QBC HQL  不分上下 都在4000左右。。

 

posted @ 2012-11-27 16:42  Onakaumi  阅读(206)  评论(0编辑  收藏  举报