Noam Nevo
Noam Nevo

Reputation: 3081

Querying Hibernate Envers revision by revision date

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.

Upvotes: 3

Views: 5903

Answers (2)

Steven Spungin
Steven Spungin

Reputation: 29109

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();

Upvotes: 5

adamw
adamw

Reputation: 8606

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.

Upvotes: 5

Related Questions