Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying all Hibernate Envers revisions between two dates

I have just started using Hibernate Envers for audit, and i will like to know if there is a way to get all the revisions of a class between two dates.

up until now i was using:

AuditQuery query = reader.createQuery().forRevisionsOfEntity(MYCLASS.class, false, true);
query.add(AuditEntity.revisionNumber().le(reader.getRevisionNumberForDate(MYDATE)));

to get the revisions of a particular date, but is there a way to recover all the revisions between for example: MYDATE1 and MYDATE2?

like image 418
PearlJam Avatar asked Feb 06 '14 00:02

PearlJam


2 Answers

You can use between method of AuditProperty to Apply a "between" constraint.

http://docs.jboss.org/envers/api-new/org/hibernate/envers/query/criteria/AuditProperty.html

like image 158
Amogh Avatar answered Oct 17 '22 23:10

Amogh


If you have a timestamp property on your @RevisionEntity you can use a query like this:

    List<Object[]> revisions = (List<Object[]>) getAuditReader().createQuery()
                .forRevisionsOfEntity(MYCLASS.class, false, true)
                .add(AuditEntity.revisionProperty("timestamp").gt(startDate))
                .add(AuditEntity.revisionProperty("timestamp").lt(endDate))
                .getResultList();
like image 45
charlb Avatar answered Oct 17 '22 23:10

charlb