Hibernate查询方案

1)  Criteria
   Criteria:面向的是POJO类
   Criterion:条件对象
        Property.forName("").xxxx();专门针对某个属性
Restriction.xxx();

  Criteria:  Criterion(1:n) 一对多关系
Criteria.add(Criterion);
2)HQL查询
          类似于SQL,面向对象(类、属性)
  from
  select
  where
  group by
  order by
  分页查询 page query
                 setFirstResult();//起始行号
setMaxResults(); 每页显示数目
from子句
StringBuffer hql = new StringBuffer("from Stduent");
Query query = se.createQuery(hql.toString());
List<Student> list = query.list();
select子句
StringBuilder hql =
new StringBuilder("selcet s.gender, s.description from Student as s");
hql.append("where s.id > 2");
Query query = session.createQuery(hql.toString());
List<Student> list = query.list();
for(int i=0; i<list.size();i++){ Object[] item = (Object[])list.get(i); System.out.print("s.gender="+item[0]); System.out.print("s.description="+item[1]); }

转自: 水晶手链

你可能感兴趣的:(POJO,sql,criterion,property)