I created a DetachedCriteria that receives objects that have isApproved and isPublished set to true . It is defined as follows:
DetachedCriteria activePublishedCriteria = DetachedCriteria.forClass(Estate.class) .add(Restrictions.eq("isApproved", true)) .add(Restrictions.eq("isPublished", true)) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
I would like to reuse these criteria in some queries. In this case, I would like to replace the limitations of isApproved and isPublished with DetachedCriteria
Criteria criteria = getSession().createCriteria(Estate.class) .createAlias("city", "c") .add(Restrictions.eq("c.id", cityID)) // the following 2 lines should use the DetachedCriteria .add(Restrictions.eq("isApproved", true)) .add(Restrictions.eq("isPublished", true)) .setProjection(Projections.rowCount()); return (Integer) criteria.list().get(0);
Is there any way to do this? Tried to use
.add(Subqueries.geAll(....
But he cannot make it work correctly. I could not find the correct documentation for the subqueries in sleep mode. Hints are welcome.
source share