Frage

I have started using Hibernate Envers for audit logging business objects. I have read the documentation and from all the examples i have seen, querying is done by revision number.

I would like to query by revision date, i.e. get all the rows of an audited entity the happened at a specific date or date range. I such a thing possible?

My revinfo table holds a timestamp so i know the data is there.

War es hilfreich?

Lösung

Yes, that is of course possible. You simply need to get the revision numbers corresponding to the dates.

This is possible either by directly querying the revision table, or using the AuditReader.getRevisionForDate method.

Andere Tipps

Use the audit reader and add query params for your dates. The property is called timestamp. This example uses an inclusive start date and an exclusive end date.

 List<Object[]> revisions = (List<Object[]>) getAuditReader().createQuery()
                .forRevisionsOfEntity(YourEntityClass.class, false, true)
                .add(AuditEntity.revisionProperty("timestamp").ge(startDate))
                .add(AuditEntity.revisionProperty("timestamp").lt(endDate))
                .getResultList();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top