java专家可以帮助我编写分离查询作为以下sql语句的条件查询的一部分.
select A.* FROM AETABLE A where not exists ( select entryid FROM AETABLE B where B.classpk = A.classpk and B.userid = A.userid and B.modifiedDate > A.modifiedDate ) and userid = 10146
解决方法
你需要编写一个
correlated subquery.假设属性/类名与上面的列/表名匹配:
DetachedCriteria subquery = DetachedCriteria.forClass(AETable.class,"b") .add(Property.forName("b.classpk").eqProperty("a.classpk")) .add(Property.forName("b.userid").eqProperty("a.userid")) .add(Property.forName("b.modifiedDate").gtProperty("a.modifiedDate")); Criteria criteria = session.createCriteria(AETable.class,"a") .add(Property.forName("userid").eq(new Integer(10146))) .add(Subqueries.notExists(subquery);