以前以为复杂的子查询只能用hql实现,今天高人指点,原来也可以用Criteria对象实现。
例如,查询a表中没有在b表出现的记录
SQL: select * from tableA a where not exists (select 1 from tableB b where b.id=a.id and b.name=**)
hibernate:
例如,查询a表中没有在b表出现的记录
SQL: select * from tableA a where not exists (select 1 from tableB b where b.id=a.id and b.name=**)
hibernate:
DetachedCriteria dCriteria = DetachedCriteria.forClass(TableB.class, "b").setProjection(Property.forName("id")).add(Expression.and(Restrictions.eqProperty("a.id", "b.id"), Expression.eq("b.name", name)));
Session.CreateCriteria(TableA.class,"a").add(Subqueries.notExists(dCriteria)).List();
复杂子查询的多种实现方式:从HQL到Criteria对象
152

被折叠的 条评论
为什么被折叠?



