我认为此链接可能很有用:http : //mikedesjardins.net/2008/09/22/hibernate-criteria-
subqueries-exists/
它包含以下有关如何创建n存在条件的示例:
“您真正想做的是获取存在相关小比萨饼的所有比萨饼订单。换句话说,您要模拟的SQL查询是
SELECt * FROM PIZZA_ORDER WHERe EXISTS (SELECt 1 FROM PIZZA WHERe PIZZA.pizza_size_id = 1 AND PIZZA.pizza_order_id = PIZZA_ORDER.pizza_order_id)
完成此 *** 作的方法是使用“存在”子查询,如下所示:
Criteria criteria = Criteria.forClass(PizzaOrder.class,"pizzaOrder");DetachedCriteria sizeCriteria = DetachedCriteria.forClass(Pizza.class,"pizza");sizeCriteria.add("pizza_size_id",1);sizeCriteria.add(Property.forName("pizza.pizza_order_id").eqProperty("pizzaOrder.pizza_order_id"));criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("pizza.id"))));List<pizzaOrder> ordersWithoneSmallPizza = criteria.list();
瞧,结果将包含两个PizzaOrders!”
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)