So I have the following code
DetachedCriteria subquery = DetachedCriteria.forClass(Component.class);
subquery.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
subquery.createAlias("files", "files");
subquery.createAlias("files.review", "review");
subquery.createAlias("review.observers", "observer", Criteria.LEFT_JOIN);
subquery.add(Restrictions.or(Restrictions.eq("review.owner", user), Restrictions.eq("observer.id", user.getId())));
subquery.setProjection(Projections.groupProperty("review.id"));
DetachedCriteria subquery2 = DetachedCriteria.forClass(ReviewNotification.class);
subquery2.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
subquery2.add(Subqueries.propertyIn("review", subquery));
subquery2.add(Restrictions.eq("reviewer", user));
subquery2.setProjection(Projections.groupProperty("review"));
Criteria criteria = session.createCriteria(Component.class);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.createAlias("files", "files");
criteria.createAlias("files.review", "review");
criteria.add(Subqueries.propertyIn("review.id", subquery2));
now my problme is that if I do the following I get 2 as a return value (this is correct)
List<Component> list = (List<Component>) criteria.list();
for (Component reviewNotification : list) {
System.out.println(reviewNotification);
}
return new Long(list.size());
but if I do
criteria.setProjection(Projections.rowCount());
return (Long) criteria.uniqueResult();
I get 4.
Anyone has any idea why the row count is failing?
I have just tried something else
criteria.setProjection(Projections.countDistinct("id"));
and this also works. So does anyone have any idea what is happening? I guess the problem is comming from criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); an I wrong?
thanks for assistance
I seems that method setProjection overrides
which would explain why return data is not unique