문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top