2 Replies Latest reply on May 14, 2010 6:45 PM by Ed Tellman

    How can I get the only the most recent version of changed entities of a particular type?

    Ed Tellman Newbie

      I was trying to figure out how to retrieve the most recent version of everything of a particular type which has changed since a particular revision.  So far I've been unsuccessful, so I was wondering if someone might be able to give me some pointers.  Here's what I've tried so far...


      This query fetches everything that has changed since the specified revision:


      AuditQuery query = auditReader.createQuery()
               .forRevisionsOfEntity(entityClass, false, true)


      If I add a maximize restriction on the revision number, I get a single item which changed at the highest revision number, which isn't what I'm looking for.


      I could do this in SQL or HQL by grouping by ID and then selecting the maximum revision from each group, but I didn't see a way to pass an HQL query to the audit reader.


      And, of course, I can use the above query and then filter out the older items from the result in Java, which is what I'm doing now.


      Anyway, I was wondering if it was possible to accomplish this by restricting the query in some way.