(一)HQL(Hibernate Query Language)查询方式:
文中Customer、LinkMan为客户和联系人类,需做好映射。
1)别名查询:
Query query = session.createQuery("from Customer c:);
List list = query.list();
2)排序查询
List list= sessioni.createQuery("from Customer order by cust_id desc").list();
3)条件查询
多属性查询:
Query query = session.createQuery("from Customer where cust_source = ? and cust_name like = ?");
query.setParameter(0,"XXX");
query.setParameter(1,"Y%");
按名称查询:
Query query = session.createQuery("from Customer where cust_source =:aaaand cust_name like :bbb");
query.setParameter("aaa","XXX");
query.setParameter("aaa","Y%");
4)投影查询:查询对象的某个或某些属性
【Hibernate(HQL、QBC和SQL查询)】多属性查询:
List
推荐阅读