I have a Hibernate criteria query that incorrectly displays maximum results. In many cases, when I specify 20 maximum results, the query actually returns only 1 or 5 results, because restrictions return a lot of duplicates.
Criteria c = session.createCriteria(DomainObject.class);
c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
c.createAlias("tags.list", "tag");
c.createAlias("names", "name");
c.createAlias("site", "site");
c.createAlias("site.tags.list", "siteTag");
// loads of or/and eq/like restrictions.
c.setFirstResult(0);
c.setMaxResults(20);
return c.list();
Is there a way to fix this query so that if I say 20 maximum results, it really returns 20 results in the county? It seems pretty crazy that hibernate limits the query to 20 results and does a separate AFTER filtering instead of the database level.
reference
source
share