1 Reply Latest reply on Jun 17, 2013 10:14 AM by adamw

    How to limit the number of retrieved revisions in a query?

    hltbdivl

      Suppose I issue a query like this: 

      {code}

      List results = AuditReaderFactory.get(entityManager)

          .createQuery()

          .forRevisionsOfEntity(MyClass.class,

              false, // [ entity, revision, change type ]

              true)  // include deletes

          .addOrder(AuditEntity.revisionNumber().asc())

          .getResultList();

      {code}

      How can I restrict the number of retrieved revisions? Note that this is different from using setMaxResults() on the query, which will restrict the number of _results_ (i.e. the number of tuples of [ entity, revision, change type ]); what I want is to place an upper bound on the number of revisions considered.  Looking at the generated SQL, I'm not so sure how this would work, as the single query is a join of both the audited entity table and the revision table, so any limit would apply to the joined results, not to the revision table alone.