0

I would like to retrieve the all recent versions of all entities( i.e. everything in Database) that has changed recently.
Following query fetch revisions of specific entity "MyEntity"

queryObject = auditReader.createQuery().forRevisionsOfEntity(MyEntity.class, false, true).addOrder(AuditEntity.revisionNumber().desc())

But I need a mechanism to fetch records for all entities irrespective of particular entity type.

Satyam
  • 703
  • 6
  • 20

1 Answers1

0

Look into org.hibernate.envers.track_entities_changed_in_revision.

This setting causes a join-table to be created against the revision-entity where a string-based set of entity names will be tracked for each revision number. With this information, you should be able to build necessary queries using the AuditReader#createQuery() API to iterate all the changes.

In pseudo code, it would be something like:

List<Number> revisions = // create AuditQuery to get all revision numbers
for ( Number revision : revisions ) {
  DefaultTrackingModifiedEntitiesRevisionEntity revisionEntity = // create query to get revision entity
  for ( String entityName : revisionEntity.getModifiedEntityNames() ) {
    // create query based on entityName + revisionNumber
  }
}
Naros
  • 19,928
  • 3
  • 41
  • 71
  • 1
    How to get all revision numbers. Should I explicitly query revchanges table for same or is there any implicit method provided by enver framework ? – Satyam Nov 15 '19 at 08:43
  • @Satyam this can help: https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#envers-querying-revision-entities – M.Ricciuti Mar 12 '21 at 09:29