Hibernate对象查询

9.如:查询订单数大于0的客户
Hibernate代码 
From Customer c where size(c.orders)>0;或者From Customer c where c.orders.size>0;

SQL语句:
Select * from customer c where 0>(select count(o.id) from order where o. customer_ID =c.id); 

10.集合过滤:
List list=session.createFilter(customer.getOrders(),“where this.price>100 order by this.price”).list();

11.对集合对象进行分页:
List list=session.createFilter(customer.getOders(),”order by this.price asc”).setFirstResult(10).setMaxResults(50).list(); 

12.检索集合中关联对象的一个属性:
List list=session.createFilter(customer.getOrders(),”select this.ordernumber ”).list(); 

13.子查询
HQL: List list=session.createQuery(“from Customer c where 1>(select count(o) from c.orders o)”).list();
SQL: Select * from Customer c where 1>(select count(o.id) from Order o where c.id=o.customer_ID);
HQL: From Customer c where 100>any(select o.price from c.orders o);  查询存在一条订单价格大于100的客户   
HQL: From Customer c where size(c.orders)>0;或者From Customer c where c.orders.size>0; 查询订单数大于0的客户
SQL: Select * from customer c where 0>(select count(o.id) from order where o. customer_ID =c.id); 

你可能感兴趣的:(Hibernate)