我有以下两个查询,它们都查询同一个表。一个查询我需要所有结果,第二个我需要一个结果的子集。最后我需要两个清单。有没有办法与第二个查询共享第一个查询。
Criteria criteriaPrStatic = this.session.createCriteria(PurchaseRequest.class).add(Restrictions.eq("inactive", false));
//Would like to use first query again and add the restrictions without having to query the table twice.
Criteria criteriaPrDynamic = this.session.createCriteria(PurchaseRequest.class).add(Restrictions.eq("inactive", false));
criteriaPrDynamic.add(Restrictions.or(
Restrictions.eq("creator", userInfo.getUser()),
Restrictions.eq("authorizer", userInfo.getUser())
));
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.groupProperty("currentState"));
projectionList.add(Projections.rowCount());
criteriaPrStatic.setProjection(projectionList);
criteriaPrDynamic.setProjection(projectionList);