I have the following two queries, both which query the same table. One query I need all the results and the second I need a subset of results. In the end I need two list. Is there a way to share the first query with the second query.
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);